js-munich-2020-spring

Lesson 10 Classwork

Let’s practice conditions. Create a guessing game

Spec

Number guessing

Hint: use if/else, typeof(), Number()

  1. Write a guessing game where you prompt the player to guess the number you predefined
  2. If the guessed number is correct, output ‘YOU WIN!’
  3. If the guessed number is too high, output ‘TOO HIGH!’
  4. If the guessed number is too low, write ‘TOO LOW!’
Bonus:
  1. If input is not a number, write ‘NOT A NUMBER!’
  2. Make number that is being guessed not predefined, but randomly generated between 1 and 10

Color guessing

Hint: use switch/case

  1. Write a guessing game where you prompt the player to guess the color you predefined
  2. If the guessed color is the same as the correct color, output “Correct!”
  3. Otherwise output ‘Try again’
Bonus:
  1. Give user 3 attempts to guess a color and then output ‘You lost’