Hey! I’m new to this whole JavaScript thing and I have to do a project for class and i can’t figure it out. here’s what it is. if any one can help that would awesome!
Concepts covered – JavaScript – For Loop & While Loops
Script 1:
Write a script that will have a user play “guess a number” with a computer. The computer will pick a number between 1 and 100. The user should then be prompted to guess a number. If the user guesses too high, print out a message stating that the number is too high. If the user guesses too low, print out a message stating that the number is too low. If the user guesses the number, print out a message stating that they won and then end the game.
Use: Javascript prompts and alerts to communicate with the user.
Use: To have the computer simulate guessing a number you will need to use a built in random number generator.
Math.floor(1 + Math.random() * 100) will produce a number from 1 to 100 – assign the result to a variable
Use: an endless while loop: while(1)
to continue prompting the user until they get the correct answer
Use: a “break” statement to get out of the while loop when the correct answer has been guessed
Script 2:
Use nested for loops to create an XHTML table which represents the multiplication times table. Be sure to print out the program using <table>.
example:
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 16 21 24 27 30
4 …
5 …
6 …
7 …
8 …
9 …
10 20 30 40 50 60 70 80 90 100