SyntaxError: Unexpected token var


#1


https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#

SyntaxError: Unexpected token var

var user = prompt("What you want to do, RUN, PAY, FIGHT").toUpperCase();

switch (user){
    
    var fast= prompt("Are you fast").toUpperCase();
    var talk =prompt("Can you talk").toUpperCase();
    
    case 'RUN':
        if(fast===yes ||talk===no){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
        break;
        
    case 'PAY':
        if(fast===yes ||talk!==no){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
        break;
        
    case 'FIGHT':
        if(fast!==yes && talk===no){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
    break;
    
    default:
       
        console.log("Say something");
        
            
    }


#2

Does anyone knows what is the problem here?


#3

These two should be outside of the switch:

yes and no in all places when checking you should have it in quotes as its a string "yes" "no"

like so:

var user = prompt("What you want to do, RUN, PAY, FIGHT").toUpperCase();

     var fast= prompt("Are you fast").toUpperCase();
     var talk =prompt("Can you talk").toUpperCase();

switch (user){
    
    
    case 'RUN':
        if(fast=== "yes" ||talk=== "no"){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
        break;
        
    case 'PAY':
        if(fast==="yes" ||talk!== "no"){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
        break;
        
    case 'FIGHT':
        if(fast!=="yes" && talk==="no"){
        console.log("Hello");}
        
        else{
         console.log("Bye");}
    break;
    
    default:
        console.log("Say something");            
    }

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.