-
Notifications
You must be signed in to change notification settings - Fork 2
add quit option, indent properly #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,68 @@ | ||
| <script> | ||
| alert("The object of this guessing is to guess how many times you will be able to correctly guess a random number between 1 and 5 within 5 tries. You will be asked your initial guess first, and then you'll guess a random number between 1 and 5 5 times. You will then recieve a message informing you of your win or your loss!"); | ||
|
|
||
| var counter = 0; | ||
| var initialGuess = prompt("If you have 5 guesses, how many times can you correctly guess a random number between 1 and 5?"); | ||
|
|
||
| Number(initialGuess); | ||
|
|
||
| while(isNaN(initialGuess) || initialGuess === "" || initialGuess > 5) { | ||
| alert("You can only guess a number between 0 and 5! Please guess again!"); | ||
| initialGuess = prompt("If you have 5 guesses, how many times can you correctly guess a random number between 1 and 5?"); | ||
|
|
||
| Number(initialGuess); | ||
| } | ||
| for (i = 0; i < 5; i++) { | ||
| var guess = prompt("Guess a number!"); | ||
| Number(guess); | ||
| while (isNaN(guess) || guess === "" || guess > 5 || guess < 1) { | ||
| alert("You can only guess a number between 1 and 5! Please guess again!"); | ||
| guess = prompt("Guess a number!"); | ||
| Number(guess); | ||
| } | ||
|
|
||
| var answer = Math.floor(Math.random() * 5 + 1); | ||
| var message; | ||
| alert("The object of this guessing is to guess how many times you will be able to correctly guess a random number between 1 and 5 within 5 tries. You will be asked your initial guess first, and then you'll guess a random number between 1 and 5 5 times. You will then recieve a message informing you of your win or your loss!"); | ||
|
|
||
| if (guess == answer) { | ||
| message = "Nice! You guessed correctly!"; | ||
| counter++; | ||
|
|
||
| var initialGuess = prompt("If you have 5 guesses, how many times can you correctly guess a random number between 1 and 5?"); | ||
|
|
||
| if (initialGuess === "q") { | ||
| alert("Goodbye!"); | ||
| } | ||
|
|
||
| else { | ||
| message = "Wrong! You guessed incorrectly! The answer was " + answer + "! Too bad, so sad..."; | ||
| } | ||
|
|
||
| alert(message); | ||
| } | ||
| Number(initialGuess); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need this line. it doesn't change "initialGuess". it returns a number, but you're not holding onto it with anything. (the next line still works fine without it) |
||
|
|
||
| while(isNaN(initialGuess) || initialGuess === "" || initialGuess > 5) { | ||
| alert("You can only guess a number between 0 and 5! Please guess again!"); | ||
| initialGuess = prompt("If you have 5 guesses, how many times can you correctly guess a random number between 1 and 5?"); | ||
| Number(initialGuess); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line also isn't doing anything. |
||
| } | ||
|
|
||
| var counter = 0, | ||
| exit = false; | ||
|
|
||
| for (i = 0; i < 5; i++) { | ||
| var guess = prompt("Guess a number!"); | ||
| if (guess === "q") { | ||
| i = 6; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
| alert("Goodbye!"); | ||
| exit = true; | ||
| } | ||
| else { | ||
| Number(guess); | ||
| while (isNaN(guess) || guess === "" || guess > 5 || guess < 1) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this while looks just like the while above. can you put it in a function and use the function in both places? |
||
| alert("You can only guess a number between 1 and 5! Please guess again!"); | ||
| guess = prompt("Guess a number!"); | ||
| Number(guess); | ||
| } | ||
|
|
||
| var answer = Math.floor(Math.random() * 5 + 1); | ||
| var message; | ||
|
|
||
| if (guess == answer) { | ||
| message = "Nice! You guessed correctly!"; | ||
| counter++; | ||
| } | ||
| else { | ||
| message = "Wrong! You guessed incorrectly! The answer was " + answer + "! Too bad, so sad..."; | ||
| } | ||
|
|
||
| alert(message); | ||
| } | ||
| } | ||
|
|
||
| if (exit) { | ||
| alert("Sorry you're a quitter."); | ||
| } | ||
| else { | ||
| if(initialGuess === counter) { | ||
| alert("Congratulations! You correctly guessed that that you would guess correctly " + counter + " out of five times! And that statement totally doesn't sound confusing at all."); | ||
| } | ||
| else { | ||
| alert("What a shame! You guessed correctly " + counter + " out of five times, but you predicted you'd guess correctly " + initialGuess + " out of five times. Oh, the Calamity!"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indent this line |
||
| } | ||
| } | ||
| } | ||
|
|
||
| if(initialGuess === counter) { | ||
| alert("Congratulations! You correctly guessed that that you would guess correctly " + counter + " out of five times! And that statement totally doesn't sound confusing at all.") | ||
| } | ||
| else { | ||
| alert("What a shame! You guessed correctly " + counter + " out of five times, but you predicted you'd guess correctly " + initialGuess + " out of five times. Oh, the Calamity!") | ||
| } | ||
|
|
||
| </script> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great change (== to ===)