If/else


#1

var user = prompt("What's your favourite food(Not dessert)?").toUpperCase();
switch(user) {
case 'CHEESE':
console.log("Nice")
break;
case 'BACON':
console.log("Same!")
break;
case 'PIZZA':
console.log("Cliché")
break;
case 'ICE CREAM':
console.log("That's a dessert")
break;
case 'BURGERS':
console.log("They're okay")
break;

default:
console.log("I like to drink... SALSA!")

};
var numLum = prompt("What's your favourite number?")
if(numLum < 3) {
console.log("Too low")
}
else if(numLum => 3) {
console.log("Too high")
}
else {
console.log("Please enter a real number")
}
var life = prompt("Would you rather be hungry or thirsty?").toLowerCase();
var height = prompt("Would you rather be tall or short?").toLowerCase();
var thirsty = if(life === thirsty) {
return true
}
else {
return false
}
var tall = if(height === tall) {
return true
}
else {
return false
}
if(thirsty && tall) {
console.log("Same!!!")
}
else if(thirsty || tall) {
console.log("Really?")
}
else {
console.log("You're the opposite of me")
}
whenever i enter this code it gives me, "SyntaxError: Unexpected token if."
does anyone know what's wrong with my code?


#2

I think this isthe unexpected token "if"
another thing that could be wrong is the }: sign under the default code


#3

@ethanator_hoffmaster,

what is this ???

 var thirsty = if(life === thirsty) {

Furthermore
edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697
[extra's]
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet