Question: I need help with this JavaScript project: 1 . Add code to ensure that all the game events stop as soon as time runs out.
I need help with this JavaScript project:
Add code to ensure that all the game events stop as soon as time runs out. This includes but is not limited to the timer, the adding of images, and the clickability of images. This part is important because the game must end at some point. Your timer should not count below
seconds.
For the gamer to play the game again, you will need to reset the score, timer, and turn on the click event for the startbutton at the end of the game. After the alert appears, calling another function to reset the game will do the trick. Though there are few ways to accomplish this.
My code:
let firstName;
firstName promptPlease enter your first name" ;
const phrase "Shall we play the game firstName ;
const instructions document.getElementByIddirections;
const newParagraph document.createElementp;
let addImageInterval;
let count ;
let score;
let seconds ;
newParagraph.innerHTML phrase;
instructions.parentNode.insertBeforenewParagraph instructions;
$documentreadyfunction Creates ready function
$#startbutton"csscolor: #aaaControls the look of the start button
'textshadow': px px black',
'fontsize':px
'fontweight':'bold',
'fontfamily':Anta sansserif',
'backgroundcolor':'white',
'borderradius':px
'width': px
;
$#startbutton"clickfunctionWhen the start button is clicked it begins the game and the button can't be clicked again
$thisoff;
beginGame;
;
$#gamespace'onclick'img', functionThis controls the score when the image is clicked and makes the image go away
$thisremove; Removes the image when it is clicked
incrementScore;
;
$#footerinfo"loadloadhtml
;
function getX This grabs the random x position for the images to appear at
return Math.floorMathrandom;
;
function getYThis grabs the random y positions for the images to appear at
return Math.floorMathrandom;
;
function randImagemin maxThis gets the random times for when the image appears
return Math.floorMathrandommax min min;
;
function incrementScoreThis is the function that makes the score work and updates the units of measure for the score
score;
if score
$#score"textscore prisoner";
else
$#score"textscore prisoners";
;
;
function beginGameThis function shows and starts the timer and adds images when the start button is pressed
$timerText'show; Shows the timer when the game starts
decrementTimer; Activates the timer when the game begins
addImage; Adds images when the game begins
function decrementTimerThis is the timer function
if seconds Stops the images and timer from continuing after the timer hits zero
clearTimeoutdecrementTimer;
clearTimeoutaddImageInterval;
else Shows the time remaining and counts down
$timerText"textseconds seconds remaining";
seconds ;
setTimeoutdecrementTimer;
function addImageThis function adds the images to the game space
let xPos getX; Gets the random positions for the images
let yPos getY;
let imgID image$count;
$#gamespace"append; Appends the image to the game space
count ;
setTimeoutfunctionFunction removes the images randomly form sec to secs
$# imgIDremove;
randImage;
addImageInterval setTimeoutaddImage randImage; Adds the image randomly from to secs
;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
