The story is heating up userAnswer trouble


#1

I have two problems with this code.
1. If I type in anything else than a number in the age question, it goes for the else answer. How can I make this check for numbers only, like isAlpha or isNumber?
2. No matter what text I write or don't write in the userAnswer prompt, it still chooses the if condition, even if my answer is not "yes". What am I doing wrong here?

Here's my code:
// Check if the user is ready to play!
confirm("Are you ready?");
var age = prompt("What's your age?");
if (age < 13) {
console.log("Be responsible, play at your own risk");
}
else {
console.log("Let's roll!");
}

// Sets a scene for the story.
console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

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


#2

1) Comparing a non-number to 13 isn't very meaningful anyway. You'll learn how to inspect the input later on I'm sure, but right now it's easier to just enter valid input.

2) You're assigning where your condition is supposed to go.


#3

Ah, right. Missing a few == there, thanks.

What I'm looking for on the first one is to check if the user-input is numerical, not non-number. I want to make sure that the users input is only numbers. Right now I can type in text and the programs puts it into the else program.
I started out with Python and now trying a bit of JS, so I'm wondering how to do this in JS too.


#4

Google it. That's the answer to any question "How do I X" "javascript test if string is number" or some such

Oh and Python is way nicer. (Not that I actually know JS)
We're just stuck with JS cause it runs everywhere.
^Opinion..


#5

With that white-space, nonono :exclamation:


#6

I blame your text editor :wink:


#7

Sublime Text 3? Wow your

BOLD

By blaming the best text editor :laughing:


#8

I'm not blaming vim, I'm blaming your $70 editor that isn't even good!


#9

$70 dollar editor??? :question: :grey_question: