Download presentation
Presentation is loading. Please wait.
Published byLars Strömberg Modified over 5 years ago
1
Basic program gives only one quess and then the program ends.
2
guessing until the user guesses the correct answer.
3
until I guess correctly.
4
the box.
5
Random number is determined outside the loop because we don't want it to change.
Guess changes so we want it in the loop. !=
6
saying TheRanNum != myGuess
7
Now I want to change the program so I allow the user to play multiple times. I will use a prompt where they can choose to play again.
8
is within the outer loop.
controls playing again.
9
The bottom diamond is checking for playAgain != N
10
This program does a document
This program does a document.write on the screen and puts up an alert box.
12
window.prompt(...) each variable an initial value. The user is then prompted to enter a number, the number is assigned to the defined variable. Then I do a calculation and store it in the variable ans. Finally I document.write the contents of the variable ans.
21
together as one. I entered 3 and 4 so concatenated they are 34.
parseFloat and parseInt are two ways to convert to a number. You have to do this when using the + because the plus has two meanings. It can mean add or it can mean concatenate. It is context driven so if we convert to numbers, it will assume the + means add. Note when I used the + without converting, the program concatenated and put the concatenated numbers in ans.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.