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
39 changes: 23 additions & 16 deletions GuessingGame.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<script>
alert("You are sitting in a bakery and smell freshly baked cupcakes. Before you can order one the cashier makes a deal with you. Pick a number between 1-100, you have 7 guesses. If you guess right you get a cupcake on the house!");

alert("You are sitting in a bakery and smell freshly baked cupcakes.
Before you can order one the cashier makes a deal with you.
Pick a number between 1-100, you have 7 guesses. If you guess
right you get a cupcake on the house!");
var answer = 42,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a way to take this further might be to select a different answer each time the game is played. the if below would have to change, then.

guess = prompt("Feeling hungry? Take a guess!")

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 two-space, soft tabs

win = false;

var answer = 42,
var guess = prompt("Feeling hungry? Take a guess!");

for(i = 0; i < 7; i++) {
for(i = 0; i < 6; i++) {
if (guess == answer) {
alert("You guessed right! Did you cheat?!")
win = true;
break;
}
else if (guess <= 30) {
guess = prompt("Brrr! You're freezing! Try again.")
}
else if (guess <= 50) {
guess = prompt("Ooooh, you're almost as warm as these cookies! Try again!")
}
else {
guess = prompt("Brrr! You're freezing! Try again.")
}
}

if (guess == answer) {
//should this be a return instead of an alert?
alert ("You guessed right! Did you cheat?!")
break;
}
else{
guess = prompt("You chose...poorly. Want to give it another go?");
if (win == false) {

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 could also write this as if (!win) rather comparing it to false

alert("LOSER!")
}
}

</script>