Switch cases - slight error


#1


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


Hey CC Squad, I've got another question. In the 'Yeah' case after I've entered 'yeah' twice, I never return the value of "Well play on playa!".

Any clues?
Cheers guys

var user = prompt("YEAH AHAA YEAH AHAA AHAA! Bad Bad Boy come with me?").toUpperCase();

switch(user){
    case 'YEAH':
       var yeahReply = prompt("Oh really?").toUpperCase(); {
           if (prompt === 'Yeah' && 'Yeah' ) {
               console.log("Well play on playa!");
               } else if (prompt === 'Maybe' || 'No') { 
                   console.log('Ahh ok, fair enough');
               }
           }
            break;
    case 'NO':
        console.log("Boo, spoil sport!");
            break;
    case 'WHAT?':
        console.log("It's a song, by these Swedish chicks from the, you know what, never mind");
            break;
    default:
        console.log("Its a song. Midi, Mmmmrrnnnnn....and Efti. Can't remember the second girl's name");
        break;
    }


#2

In the 'Yeah' case after I've entered 'yeah' twice, I never return the value of "Well play on playa!"

There's an error .. (Even overall code is passed by CC editor)

if (prompt === 'Yeah' && 'Yeah' )

prompt is not a variable.
It should be yeahReply that should be compared!

I hope it helps!


#3

Hey, that makes sense @greentreemee i gave that a go, but still even if i reply yeah both times i only get the else if response. I have a feeling that I may need a third prompt to be able to respond 'Yeah' twice in order to get the 'Yeah' && 'Yeah' response of 'Well play...'.

I'll play around with it


#4

Because you're making a compound condition using &&.
It simply means that to execute that block of code, two condition should be true.
It should be 'Yeah' and also'yeah'.
Even you use || operator, It will let you execute that block but then again your code will throw an error saying You did not used && operator.
To deal with that you can add a new storyline that'd take two essential conditions (You can combine them using &&)

I hope it makes your doubt more clear! :slight_smile:


#5

Ahhh i changed one slight thing, which was the 'Yeah' 's in the IF prompt to 'YEAH'. I think because it had .toUpperCase it changing the inputs to capitalised when the defined Yeah's were lowercase. It works now! Thanks for sticking with me!


#6

Keep up the good work! :thumbsup:


#7

cheers, really appreciate the help!


#8

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