Creating Feedback option - Error


#1

Hi,
I have been very much enjoying creating my initial attempt at the game and have got as far as the feedback stage. I have created the if/else for the response and keep getting an error message stating - Syntax Error Unexpected Identifier.
Please could you take a look at my code below and let me know where Im going wrong.

Thanks

// Check if the user is ready to play!
confirm("Are you ready to play?");
//Check the user's age with a prompt
var age = prompt ("What's your age?");
//Use if/else to deny responsibility for under 13's
if(age<13){
console.log("This game may not be suitable for younger players, the creator takes no responsibility for any disturbance caused");
}
else
{
console.log("Welcome to Kerrie's Game. I hope you enjoy yourself!!");
}
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?'");
//Check whether user wants to race
var userAnswer = prompt("Do you want to race Bieber on stage? Type Y or N");
// Give 2 options as to what happens when they make a decision
if (userAnswer === "y" or "Y"){
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.'");
}
//Create an option to leave feedback and thank them for high rating using an if/else
var feedback = prompt("Please rate the game out of 10");
if (feedback >>> 8) {
console.log("Thank you! We should race at the next concert");
}
else
{
console.log("I'll keep practising my coding!");
}
//Create feedback option and response message
var feedback = prompt("Please rate the 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.");
}


#2

@kerrie_hector84 try define y or n as -

var =y;
var =n;
and then use if statement

since i m too noob at programing, i m giving u my pint of view


#3

Hi, thanks for your reply. The yes/no part is working. The code only stopped working when I added on the feedback part. Its something about the last variable (feedback) and its if/else statement that is the issue but I cannot for the life of me see what it might be!


#4

@kerrie_hector84 Here's ur code

// Check if the user is ready to play!
confirm("Are you ready to play?");
//Check the user's age with a prompt
var age = prompt ("What's your age?");
//Use if/else to deny responsibility for under 13's
if(age<13){
console.log("This game may not be suitable for younger players, the creator takes no responsibility for any disturbance caused");
}
else
{
console.log("Welcome to Kerrie's Game. I hope you enjoy yourself!!");
}
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?'");
//Check whether user wants to race
var userAnswer = prompt("Do you want to race Bieber on stage? Type Y or N");
// Give 2 options as to what happens when they make a decision
var Y;
var N;
if (userAnswer === "Y"){
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.'");
}
//Create an option to leave feedback and thank them for high rating using an if/else

var feedback = prompt("Please rate the 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.");
}


#5

@kerrie_hector84 i have made some ammendents, it's about declaring 'Y' & 'N'...


#6

Ohhhh, I see, though I'm still uncertain why it initially worked before I added the feedback stage but then need the Y and N variables after it was added. Anyway, thank you very much!! I can carry on enjoying myself now! :smile:


#7

@kerrie_hector84 i think it worked coz, program was not using the variable y or n , but later it need it to compare . When it realize that y or n is not define how it gonna compare it shows error.

it's just my opinion don't know it's right or wrong!!
Happy Coding