Code Your Own Adventure Game exercise: Only displaying "yes" scenarios?


#1

Hello again,

I have passed through the CYOAG exercise with the Justin Bieber game, however despite Codecademy saying I passed I have noticed that on certain if / else statements it is always giving me the "if" outcome rather than the "else" no matter what I type in the prompt box that pops up. I will copy and paste my code below:

confirm("Are you ready to play?");

var age = 13;
var age = prompt("How old are you?");

if
(age < 13) {
console.log("Sorry, you are too young.")
}

else
{
console.log("Ok, you may enter.")
}
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'")

console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")

var userAnswer = "yes";
var userAnswer = prompt("Do you want to race Bieber on stage?");

if
(userAnswer === "yes") {
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!")
}
else
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'")
}

var feedback = 10;
var feedback = prompt("Please rate this game out of 10!");

if
(feedback >= 8) {
console.log("Thank you! We should race at the next concert!")
}

else
{
console.log("I'll keep practicing coding and racing.")
}

It seems to be where the prompt asks the player if they want to race Bieber, I have declared the userAnswer to be yes of the "if", but even if I type no the console log still displays as if I have answered yes.

Is this a mistake I am making somewhere in the code or just a glitch? I am a tad confused as it is still saying I have passed despite this error being present.

If anyone else has an idea of what is going on, please do enlighten me so that I may promptly correct the mistake. I want to get to work on creating some of my own text-based adventure games and so, ya know, the sooner the better :smile:

Thanks in advance for reading and I look forward to your replies.

Cheers


#2

You are redeclaring the same variables way to much....


#3

Could you elaborate please?

I have followed the exercise step by step and am being told that what I'm doing is correct. Also each variable (age, userAnswer, feedback) have each only been declared once... Unless I'm missing something


#4

These two statements are both declaring the variable age. You do not need the first one since it is being declared when the user enters an answer in your prompt box. Same with your feedback variable.

var age = 13;
var age = prompt("How old are you?")