Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 52 additions & 37 deletions guessGame.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,60 @@
<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!");
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;

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);
}
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?");
}
var counter = 0,
exit = false;
for (i = 0; i < 5; i++) {
var guess = prompt("Guess a number!");
if (guess === "q") {
break;
alert("Goodbye!");
exit = true;
}
else {
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;

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!");
}
}
}

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>