The story heats up


#1

The story heats up!
Now you have to create different scenarios. Good thing we know how to do that using if / else statements.

If userAnswer is "yes", print out: "You and Bieber start racing. It's neck and neck! You win by a shoelace!"

Otherwise, print out: "Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'"

Remember: = is for assignment, and === is to check if things are equal!

Instructions
Use an if / else statement to write out the last part of this game!

Make sure to check the console for error messages and suggestions for how to fix them.


#2

Hello @shriharip,

Do you care to share the code you've tried out for this exercise?

Thank you! :slight_smile:


#3

I cant understand what to give inside as if conditional check..and secondly to check the console for error msg and how to fix it...


#4

var userAnswer = prompt("Do you have any error mg");
if (userAnswer === "last part")
{
console.log("turn off");
}
else
{
console.log("continue");
}


#5

The instructions ask you to code something.

This would be your if condition. Make sure to write it so that it makes sense in javascript. Then:

What could you use to make those sentences log to the console?

Your else statement won't take a condition but it should log something to the console. Something like the other phrase given in the instructions. Hope this helped :slight_smile:


#6

I'm having similar trouble! My code is here:

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.'")
}

But it says there's a syntax error. I'm sure it's something silly, but I can't figure it out! Help? :slight_smile:


#7

@fbirobby the above is from the instructions. Now let's look at your code below:

Change your = sign to the === and resubmit.


#8

Thank you so much!! :slight_smile:

So I tried it, and unfortunately it didn't work! There's apparently still a syntax problem:

confirm("Click OK to play our game!")

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

if(age is less than 13)
{
console.log("We totes aren't liable, breh")
}
else
{
console.log("Hellz yea let's play")
}

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 = 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.'")
}

This is all the code I have. Really confused?


#9

Try putting the yes in quotation marks for:


#10

Still nothing... Syntax error :frowning:


#11

This isn't written in a way that javascript will accept.


#12

FINALLY!! Thank youuuuuuu


#13

I can't believe I missed that :smile:


#14

A post was split to a new topic: My code is Error!


#15