5/6 logical operators


#1

var user = prompt("Do you wanna play a game? YES/NO or Maybe").toUpperCase();

switch(user)
{
case 'YES' :
console.log("then, Let's play the game.");
var coin = Math.random();
if(coin <= 0.5)
{
console.log("You got tail. you be alive")
};
else
{
console.log("You got face. you be dead")
};
break;
case 'NO' :
console.log("You have already been trapped, you cannot escape.");
var coin = Math.random();
if(coin <= 0.5)
{
console.log("You got tail. you be alive")
};
else
{
console.log("You got face. you be dead")
};
break;
case 'MAYBE' :
console.log("There is no maybe. you are playing the game.");
var coin = Math.random();
if(coin <= 0.5)
{
console.log("You got tail. you be alive")
};
else
{
console.log("You got face. you be dead")
};
break;
default :
console.log();
};

I got unexpected token else. why?


#2

Everywhere you see,

};
else {

remove the semi-colon. We never write a ; before else. In fact there are no semi-colons anywhere in an if-else statement except within the code block, itself, on the statements that require it.

if (condition) {
    // code statements for `true`
} else {
    // default code statements
}