5.Logical operators


#1


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


Hi, I'm having trouble finding whats wrong with my code. The error message says unexpected identifier and I would really appreciate it if you guys could point out whats wrong with my code.


var user = prompt("You are dribbling down the basketball court and you have three options, shoot, pass or drive for the lay up ").toUpperCase();
switch(user) {
    case 'Shoot':
        var shooter = prompt("Are you good at shooting?(YES or NO)").toUpperCase();
        var space = prompt("Are you in a good position to shoot?").toUpperCase()
        if(shooter === 'YES' || space === 'YES'){
        console.log("Swish")
        }else{
            console.log("You airball the shot")
        }
        break;
    case 'Pass':
        var passing = prompt("Are you good at passing?(YES or NO)").toUpperCase();
        var opposition = prompt("Is there any opposition between your teammate and you?").toUpperCase()
        if(passing === 'YES'&& opposition === 'NO'){
        console.log("Your team mate makes a 3-pointer");
        }else{
            console.log("The other team make the interception and get the ball");
        }
        break;
    case 'Drive for the lay-up':
        var drive = prompt("Are you good at making lay-ups?(YES or NO)").toUpperCase();
        var lay up = prompt("Is there anyone in your way?").toUpperCase();
        if(drive === 'YES' || lay up === 'NO'){
            console.log("You make the basket!")
        }else{
        console.log("You get blocked just under the basket");
        }
        break;
    default:
    console.log("Thats not one of the options");}


#2

change this case toPASS and not Pass

and also change this case,

toDRIVE FOR THE LAY-UP and not Drive for the lay-up because the first line of your code takes user input and changes all characters to upper case characters,


#3

Hi,
Thanks for the help, I made the changes you suggested but the error message stills says unexpected identifier. Do you have any idea why this might be?


#4

Your first case as well needs to be SHOOT and not Shoot all in all it should look something like,

var user = prompt("You are dribbling down the basketball court and you have three options, shoot, pass or drive for the lay up ").toUpperCase();
switch(user) {
    case 'SHOOT':
        var shooter = prompt("Are you good at shooting?(YES or NO)").toUpperCase();
        var space = prompt("Are you in a good position to shoot?").toUpperCase()
        if(shooter === 'YES' || space === 'YES'){
        console.log("Swish")
        }else{
            console.log("You airball the shot")
        }
        break;
    case 'PASS':
        var passing = prompt("Are you good at passing?(YES or NO)").toUpperCase();
        var opposition = prompt("Is there any opposition between your teammate and you?").toUpperCase()
        if(passing === 'YES' && opposition === 'NO'){
        console.log("Your team mate makes a 3-pointer");
        }else{
            console.log("The other team make the interception and get the ball");
        }
        break;
    case 'DRIVE FOR THE LAY-UP':
        var drive = prompt("Are you good at making lay-ups?(YES or NO)").toUpperCase();
        var lay_up = prompt("Is there anyone in your way?").toUpperCase();
        if(drive === 'YES' || lay_up === 'NO'){
            console.log("You make the basket!")
        }else{
        console.log("You get blocked just under the basket");
        }
        break;
    default:
    console.log("Thats not one of the options");
}
}

#5

Thanks that really helped!


#6

You're welcome :slight_smile:


#7

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