Question

Hello, I'm getting a error for my JavaScript text based game. Please fix. var name =...

Hello, I'm getting a error for my JavaScript text based game. Please fix.

var name = prompt("What is your name?");


var choice1 = prompt("Hello "+name+" you see two houses which one do you enter? house 1 or house 2?");

confirm("you chose to open "+choice1);

if(choice1 === "house 1")
{
confirm("You entered house 1");

choice1 = prompt("You find a key on the porch want to pick it up? yes or no");

if(choice1 === "yes"){
    confirm("You picked up the key!");
    confirm("You went inside !");
}

else if(choice1 === "no"){
    confirm("You didnt pick up the key!");
    confirm("You didn't enter house!");
}

}
else if (choice1 === "house 2")
{
confirm("You entered house 2");

choice1 = prompt("You find a sleeping sleeping lion? run or walk");

if(choice1 === "run"){
    confirm("You ran from the lion!");
    confirm("The lion woke and got you!");
}

else if(choice1 === "walk"){
    confirm("You walked slowly out the house");
    confirm("You didnt wake the lion!");
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//note your input should be same as given in if condition... like house 1,house 2

<script>
var name = prompt("What is your name?");


var choice1 = prompt("Hello "+name+" you see two houses which one do you enter? house 1 or house 2?");

confirm("you chose to open "+choice1);

if(choice1 === "house 1")
{
confirm("You entered house 1");

choice1 = prompt("You find a key on the porch want to pick it up? yes or no");

if(choice1 === "yes"){
confirm("You picked up the key!");
confirm("You went inside !");
}

else if(choice1 === "no"){
confirm("You didnt pick up the key!");
confirm("You didn't enter house!");
}

}
else if (choice1 === "house 2")
{
confirm("You entered house 2");

choice1 = prompt("You find a sleeping sleeping lion? run or walk");

if(choice1 === "run"){
confirm("You ran from the lion!");
confirm("The lion woke and got you!");
}

else if(choice1 === "walk"){
confirm("You walked slowly out the house");
confirm("You didnt wake the lion!");
}

}
</script>

Add a comment
Know the answer?
Add Answer to:
Hello, I'm getting a error for my JavaScript text based game. Please fix. var name =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT