Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your title goes here

ID: 3656391 • Letter: Y

Question

, and you could make the dialog at the end more expansive as well. But don't do that until you have the basic program working. This is the specification of what your program must do: When your program starts up it must display the image that will move around, a Start button, a Stop button, and a way for the user to specify an interval before a new game begins. The default interval must be 1000 msec. When the user presses Start, a new game starts and the selected image is displayed at a random place. The image must move to a new random place once per interval. If the user presses the Stop button, the image must stop moving, and a subsequent Start must start everything over from the beginning. Each time the user successfully hits the image, the program must move the image to a new random place immediately (i.e., not wait for the current interval to end). When the user has hit the image 3 times, the program must display a confirm dialog box that reports the elapsed time in seconds and that also says something like "Another game?" If the user pushes OK, that starts a new game immediately (no need to push Start again). If Cancel is pushed, the program stops. The items are listed in this specification in the order in which it seems easiest to write the program. Do each piece and make it work before worrying about the next one. Each component of the user interface has a name in the Javascript program; your interface doesn't have to look like the one above, but you must use the specified names for variables and functions ("hit" and "hitcount" are different!). Don't use the name "int" for a variable; it's a reserved word in some versions of Javascript. Template It can be hard to keep all the pieces straight, especially when you're new to programming, so we're giving you a template for organizing your program. Your job is to figure out the proper statements to replace the comments in the template. Try to think clearly about what operation or operations each part must do, as implied by the spec above. This link points to the template lab6.html. Create your own HTML file lab6.html by downloading the template directly (right click in Windows, Option click in Mac) and then start replacing the commented parts by your own code, in the order suggested above. Copy and paste example code from the instructions, then modify it appropriately. Follow this template to organize your page! We've tried to make this orderly and easy to follow. Do not ignore it. Your title goes here msec // declare your variables here: hitcount, setint_val, starttime, ... function newgame() { // your code to set up for each new game goes here: // clearInterval(setint_val) to reset the interval set by a previous game // set hitcount to 0 // call setInterval() to set the interval from the value in the form // initialize starttime, the starting time, using new Date() } function moveit() { // your code to move your image goes here: // move the image, using the code given below } function hit() { // your code to handle each successful hit goes here: // move the image with moveit() // clearInterval(setint_val) to reset the interval // call setInterval() to set the interval again // add 1 to hitcount if (hitcount >= 3) { // clearInterval() to stop the image from moving // compute the elapsed time (make another call to new Date()) // confirm() to display time and ask about another game // if another game is to be played // newgame() } }

Explanation / Answer

7cd44718519832fed7a31ed6b7610ff9b8beb025fe753ce04633d8c71d706fc0