select Yes if the code segment above causes the page to behave as described

HOTSPOT
You review code that uses WebSockets for a browser-based multiplayer game. Each player sends a
move to the server, which then sends the move to all connected game instances. The following code
runs in the browser and handles the sending and receiving of moves:

For each statement in the table, select Yes if the code segment above causes the page to behave as
described. Select No if it does not. Make only one selection in each column.

HOTSPOT
You review code that uses WebSockets for a browser-based multiplayer game. Each player sends a
move to the server, which then sends the move to all connected game instances. The following code
runs in the browser and handles the sending and receiving of moves:

For each statement in the table, select Yes if the code segment above causes the page to behave as
described. Select No if it does not. Make only one selection in each column.

Answer:



Leave a Reply 6

Your email address will not be published. Required fields are marked *


rik

rik

And the award for “Most. Incomplete. Code or Question. Ever.” goes to…

If this is the code, then all descriptions are a no. Since server.onopen will fail on the fact that getUserName() is an undefined function (and then there’s the small matter of the function sendMove() not being invoked etc.).

Are we being asked to base our guess on the assumption that everything that is missing is defined elsewhere..? Then it’s backward, and all descriptions might as well be a yes.

Who is to say, when you send your move to the server, it is then not returned by said server and added to the moveList array when the onmessage event occurs?

And then there’s getMove(). I wonder what that does…

strongmmc

strongmmc

yes, getUserName() and getMove() should be defined somewhere else.

answering the third question:

The thing is that when the move is made, hence the (hypothetical) complex object is generated, an id for that object is also generated. The move is then added in the array of the player moves using the id of said object as the index (or key) to store it.
When its then broadcasted by the server, it returns to the player that made that move, and the onmessage handler checks whether or not that id corresponds to an allocated object in the local moves array/dictionary. When the message arrives and its id is not one of mine, i add the message in the array. Therefore, all the messages the came from me won’t ever be added in the moveList, and there’s your answer to the third question.

obviously i wouldn’t ever expect to use a ‘long’ for this id. i would need something more like a ‘guid’.

J

J

(irony aside ) I agree this is very unprofessional from ms to create exams such as this.

J

J

.. but the answer looks correct 🙂

Levi

Levi

“The player’s own moves will be added to moveList array”

No, it won’t. Where is that code? In onMessage? No, that’s adding the move if it is NOT the user’s move. .. I fink

anii

anii

The answer “No” is circled. So you & Microsoft agree 😉