Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count down dialog #19

Open
5 tasks
jugglinmike opened this issue Sep 25, 2014 · 0 comments
Open
5 tasks

Count down dialog #19

jugglinmike opened this issue Sep 25, 2014 · 0 comments
Milestone

Comments

@jugglinmike
Copy link
Collaborator

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:

      1. Decrement (decrease by 1) the timeLeft variable

      2. If the timeLeft variable is 0, call the Director's start method
        and return.

      3. Update the innerHTML of the countdownEl to:

        `timeLeft + ' second(s)'

      4. 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"?

@jugglinmike jugglinmike modified the milestone: Game state 1 Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant