From 8d37e3578d3ff4893e65c0689fd71ca04d4f589f Mon Sep 17 00:00:00 2001 From: Katie Reid Date: Tue, 6 Jan 2015 15:32:54 -0800 Subject: [PATCH 1/2] add quit option, indent properly --- guessGame.html | 97 +++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/guessGame.html b/guessGame.html index 30713c0..10f0655 100644 --- a/guessGame.html +++ b/guessGame.html @@ -1,45 +1,68 @@ From ad9286783a7d4076b333a93e9182eef188a4611d Mon Sep 17 00:00:00 2001 From: Katie Reid Date: Wed, 14 Jan 2015 12:33:48 -0800 Subject: [PATCH 2/2] update game with mels suggestions --- guessGame.html | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/guessGame.html b/guessGame.html index 10f0655..9020b73 100644 --- a/guessGame.html +++ b/guessGame.html @@ -10,21 +10,16 @@ else { - 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); } - var counter = 0, exit = false; - for (i = 0; i < 5; i++) { var guess = prompt("Guess a number!"); if (guess === "q") { - i = 6; + break; alert("Goodbye!"); exit = true; } @@ -35,22 +30,19 @@ guess = prompt("Guess a number!"); Number(guess); } - var answer = Math.floor(Math.random() * 5 + 1); var message; - if (guess == answer) { + 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."); } @@ -59,7 +51,7 @@ 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!"); + 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!"); } } }