Switch statemet . want to hav an if /else statement in a switch case


#1

var user = prompt("what are you doing?").toUpperCase();

switch(user)
{
case 'play':
i=1
if(user === 'PLAY' && i === 1)
console.log("Healthy");
else("unhealthy");
break;

case 'eat':
i=1;
if(user ===' EAT' || i = 1)
console.log("Healthy");
else("unhealthy");
break;

case 'sleep':
console.log("8 hrs");
break;

default :
console.log("not interested");
break;
};

ReferenceError: invalid assignment left-hand side: please help


#2

In your case "eat", in the condition you wrote i=1. However "=" is only used for variable assignments. Inside conditions you want to use "===" which is a comparison operator (just like you did in the first case.