I am doing this code:
confirm(“I am ready to play!”);
var age = prompt (“What’s your age?”) ;
if (age < ) {
console.log (“Proceed at your own risk”);
} else {
console.log (“Good Luck”);
}
console.log (“You wake up in a cave and find yourself trapped in a room and find a torch and a door”) ;
console.log (“Be sure to choose the right one”);
userAnswer = prompt (“Do you take the door or the torch?”);
if (userAnswer===”torch”) {
console.log (“You take the torch and walk down the cave now that you can see”);
} else {
console.log (“You open the door only to see a brick wall in your way so you take the torch and go on”);
}
userAnswer = prompt (“Your torch is now losing its flame, do you either keep on going or walk through a nearby door”);
if (userAnswer ===”keep going”) {
console.log (“You keep going and your flame runs out, you hear noises coming towards you and then run back and go through the door. The door leads you to a teleporter which you jump through and end up in the batcave”);
} else {
console.log (“You chose to take the door which leads to a stairway to the batcave”);
}
userAnswer = prompt (“You are now in the batcave and see Batman, do you either ask him to lead you back home or attemp to fight him”);
if (userAnswer===”fight him”) {
console.log (“You attempt to fight Batman and he wins because he is batman. Now he knocks you out and throws you to the bottom of the batcave”);
} else {
console.log (“You ask batman for the way out and he drives you out of the cave and back home in his batmobile”);
}
var feedback = prompt (“Rate the game -“);
if (feedback > ) {
console.log (“Thanks for enjoying this game!”);
} else {
console.log (“I slaved away at this game and you gave me that score?! The nerve! Just you wait”);
}
Everything seems to run perfectly when I run it except some parts of it won’t show up like the story when it says console.log and then the message I want them to see doesn’t show up. The only parts that pop are the user answers and the feedback. My question is, how do I get all of the messages (console.log) to show up when I run the code?
Answer
? Favorite Answer
The HTML code (with your Javascript replacing all console.log with alert) worked well for me:
<html>
<head>
<body>
<script>
confirm(“I am ready to play!”);
var age = prompt (“What’s your age?”) ;
if (age < ) {
alert (“Proceed at your own risk”);
} else {
alert (“Good Luck”);
}
alert (“You wake up in a cave and find yourself trapped in a room and find a torch and a door”) ;
alert (“Be sure to choose the right one”);
userAnswer = prompt (“Do you take the door or the torch?”);
if (userAnswer===”torch”) {
alert (“You take the torch and walk down the cave now that you can see”);
} else {
alert (“You open the door only to see a brick wall in your way so you take the torch and go on”);
}
userAnswer = prompt (“Your torch is now losing its flame, do you either keep on going or walk through a nearby door”);
if (userAnswer ===”keep going”) {
alert (“You keep going and your flame runs out, you hear noises coming towards you and then run back and go through the door. The door leads you to a teleporter which you jump through and end up in the batcave”);
} else {
alert (“You chose to take the door which leads to a stairway to the batcave”);
}
userAnswer = prompt (“You are now in the batcave and see Batman, do you either ask him to lead you back home or attemp to fight him”);
if (userAnswer===”fight him”) {
alert (“You attempt to fight Batman and he wins because he is batman. Now he knocks you out and throws you to the bottom of the batcave”);
} else {
alert (“You ask batman for the way out and he drives you out of the cave and back home in his batmobile”);
}
var feedback = prompt (“Rate the game -“);
if (feedback > ) {
alert (“Thanks for enjoying this game!”);
} else {
alert (“I slaved away at this game and you gave me that score?! The nerve! Just you wait”);
}
</script>
</body>
</html>