jamessullivan77
jamessullivan77

Reputation: 39

If/Else Statement

Hi what am I doing wrong with this if statement? Ive tried making the second one and else if and the last one an else as well but cant get the alerts to respond properly.

prompt("Please enter a number");
if(x < 100) {
    alert("variable is less 100")
}
if(x == 100) {
    alert("variable is equal to 100!")
}
if(x > 100) {
    alert("variable was greater than 100")
}

thanks!

Upvotes: 1

Views: 47

Answers (1)

Nina Scholz
Nina Scholz

Reputation: 386520

You are missing an assignment to variable x.

var x = prompt("Please enter a number");
//^^^^^

Then you could use parseInt to get a integer number from the string

x = parseInt(x, 10);

Upvotes: 7

Related Questions