You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The beginning is a little abrupt, isn't it? The spec calls for a "countdown"
screen to give the user a chance to prepare themselves after clicking "begin".
Let's build that.
director.js
Define a method called countdown on the Director prototype
In the countdown method, set the innerHTML of the el to contain
(at least) the following markup:
'Game beginning in '
Feel free to embellish with extra markup and style!
Grab that span element (just like you did with the <button> element
in the previous exercise) and store it in a variable called countdownEl.
Define a local variable called timeLeft and initialize it to be the
number of seconds the timer should start at.
Define an update function inside the countDown method (yup, a
function inside a method). This should do the following:
Decrement (decrease by 1) the timeLeft variable
If the timeLeft variable is 0, call the Director's start method
and return.
Update the innerHTML of the countdownEl to:
`timeLeft + ' second(s)'
Use setTimeout to call update again in 1 second (remember, setTimeout expects millisecond values!)
That last part is a little tricky--the update method calls itself! In
programming, we say that a function that calls itself is "recursive".
Anyway, the timer is okay, but the whole "second(s)" thing is a little cheap.
Can you update it so that it says "Game beginning in 2 seconds" and then "Game
beginning in 1 second"?
The text was updated successfully, but these errors were encountered:
The beginning is a little abrupt, isn't it? The spec calls for a "countdown"
screen to give the user a chance to prepare themselves after clicking "begin".
Let's build that.
director.js
Define a method called
countdown
on the Director prototypeIn the
countdown
method, set theinnerHTML
of theel
to contain(at least) the following markup:
'Game beginning in '
Feel free to embellish with extra markup and style!
Grab that
span
element (just like you did with the<button>
elementin the previous exercise) and store it in a variable called
countdownEl
.Define a local variable called
timeLeft
and initialize it to be thenumber of seconds the timer should start at.
Define an
update
function inside thecountDown
method (yup, afunction inside a method). This should do the following:
Decrement (decrease by 1) the
timeLeft
variableIf the
timeLeft
variable is0
, call the Director'sstart
methodand return.
Update the
innerHTML
of thecountdownEl
to:`timeLeft + ' second(s)'
Use
setTimeout
to callupdate
again in 1 second (remember,setTimeout
expects millisecond values!)That last part is a little tricky--the
update
method calls itself! Inprogramming, we say that a function that calls itself is "recursive".
Anyway, the timer is okay, but the whole "second(s)" thing is a little cheap.
Can you update it so that it says "Game beginning in 2 seconds" and then "Game
beginning in 1 second"?
The text was updated successfully, but these errors were encountered: