Girl Develop It Buffalo

JS101 Class 2 Homework: Number Guesser

Home

You'll create a simple number guessing game where the user gets infinite tries to guess the number.

  • Generate a random whole number and store it in a global variable
  • Create another global variable to store if the user has won or not
  • Write a function called guessNumber that will:
    • Take one argument, the guessed number.
    • If the guessed number is less or greater than the target number indicate that to the user
    • If the guessed number and the target number match, congratulate the user
    • Ask for their name and add the user to the list of winners and display the list to the user
    • Ask the user if they want to play again, if so generate a new target number, if not update the win variable such that the loop stops
  • Inside a loop prompt the user for a guess and call your guessNumber function while the win variable is false
  • Hints:Look at your cheatsheets for the Math functions to generate random whole numbers
  • Bonus: turn the game loop into a recursive function