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
97 changes: 60 additions & 37 deletions guessGame.html
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") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great change (== to ===)

alert("Goodbye!");
}

else {
message = "Wrong! You guessed incorrectly! The answer was " + answer + "! Too bad, so sad...";
}

alert(message);
}
Number(initialGuess);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use break; instead of setting i to 6

alert("Goodbye!");
exit = true;
}
else {
Number(guess);
while (isNaN(guess) || guess === "" || guess > 5 || guess < 1) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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!");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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>