Unexpected token ILLEGAL


#1

var user = prompt("What is your favorite chocolate?", "Type your favorite chocolate here").toUpperCase();
switch(user) {
case 'DAIRYMILK':
var cost = prompt("What cost of chocolate you want?", "Type either <50 or >50?");
if (cost < 50 && cost > 50) {
console.log("You won Rs.50 chocolate!");
} else if ( cost < 50) {
console.log("You won Rs.20 chocolate!");
} else {
console.log("You won Rs.70 chocolate!);
}
break;
// Add your code here!
case 'KITKAT':
console.log("Superb chocolate.... but it's cost is too high!");
break;
case 'MUNCH':
console.log("Crunchy to eat...... ");
break;
case 'MILKYBAR':
var taste = prompt("What type of chocolate you like?", "Type any two of crunchy, choco, light");
if (taste === crunchy || taste === light) {
console.log("you like crunchy and light chocolate!");
} else if (taste === choco || taste === light) {
console.log("You like choco & light combination chocolate!");
} else {
console.log("Cho choo chweet..... normal milkybar chocolate!");
}
break;
default:
console.log("Your favorite chocolate isn't exist!");
}


#2
var user = prompt("What is your favorite chocolate?", "Type your favorite chocolate here").toUpperCase();
switch (user) {
    case 'DAIRYMILK':
        var cost = prompt("What cost of chocolate you want?", "Type either <50 or >50?");
        if (cost < 50 && cost > 50) { // condition is impossible to be fulfilled
            console.log("You won Rs.50 chocolate!");
        } else if (cost < 50) {
            console.log("You won Rs.20 chocolate!");
        } else {
            console.log("You won Rs.70 chocolate!"); // added closing quotes "
        }
        break;
        // Add your code here!
    case 'KITKAT':
        console.log("Superb chocolate.... but it's cost is too high!");
        break;
    case 'MUNCH':
        console.log("Crunchy to eat...... ");
        break;
    case 'MILKYBAR':
        var taste = prompt("What type of chocolate you like?", "Type any two of crunchy, choco, light");
        if (taste === crunchy || taste === light) {
            console.log("you like crunchy and light chocolate!");
        } else if (taste === choco || taste === light) {
            console.log("You like choco & light combination chocolate!");
        } else {
            console.log("Cho choo chweet..... normal milkybar chocolate!");
        }
        break;
    default:
        console.log("Your favorite chocolate isn't exist!");
}

The condition

if (cost < 50 && cost > 50)

can never be fulfilled because the variable cost can only store one value. And that value can't be < than 50 and > than 50 at the same time.


#3

var user = prompt("What is your favorite chocolate?", "Type your favorite chocolate here").toUpperCase();
switch(user) {
case 'DAIRYMILK':
var cost = prompt("What cost of chocolate you want?", "Type either <50 or >50?");
if (cost < 50 && cost > 50) {
console.log("You won Rs.50 chocolate!");
} else if ( cost < 50) {
console.log("You won Rs.20 chocolate!");
} else {
console.log("You won Rs.70 chocolate!); //HERE
}
break;

Where is your closing double quotes?


#4

Thank you so much for explain this problem.