Project Activity 4: Javascript Control Flow and Functions
Project Activity 4: Javascript Control Flow and Functions
Number Guessing Game
Create a simple number guessing game using JavaScript. The game should generate a random number between a specified range and allow the user to input their guess. The game should provide feedback to the user if their guess is too high or too low, and inform them when they guess the correct number.
Here’s a basic outline to get you started:
- Generate a random number between a specified range using the Math.random() function and some basic arithmetic operations.
- Prompt the user to enter their guess using the prompt() function or by creating an input element in the HTML file.
- Compare the user’s guess with the generated random number and provide appropriate feedback. You can use conditional statements (if…else) to check if the guess is too high, too low, or correct.
- Repeat steps 2 and 3 until the user guesses the correct number. You can use a loop (such as a while loop) to keep the game running until the correct guess is made.
- Once the correct guess is made, display a congratulatory message to the user and give them the option to play again.
Feel free to add more features to the game, such as keeping track of the number of guesses the user has made or setting a time limit for each guess. Customize the design and user interface to make the game more engaging and visually appealing.
Have fun coding and enjoy playing the number guessing game!