My 'if' statement inside switch doesn't work. Any advice for me?


#1

Below is my game. When player answers 'Nih' a second prompt re: 'shrubbery' should happen. Instead I get default response at bottom every time. Does anyone know what is wrong here?

var answer = prompt("You walk across a bridge & a knight is there. What do you say to him?").toUpperCase();

switch(answer){
    case 'Got a quarter?':
        if(answer == 'Got a quarter?' && answer.length ==4)         {
            console.log("Here you are");
        }
        else {
           console.log("Stop bludging!");
        }
        break;
    case 'Gimmee Shelter':
        console.log("Whooh whoooh");
        break;
    case 'Nih':
        if(answer == 'Nih'){
            prompt("Do you have a shrubbery?");
            }
            if(answer=='Yes'||'no'){
            console.log("We are the knights who say Nih!");
        }else{
            console.log("Bugger off");
            break;
        }
    default:
        console.log("I intend to jump");
        break;
        };

#3

Would be nice if you indent your code


#4

It actually was indented when pasted in. When I go in to edit it the indents are still there so I can't change it. It's still readable enough for someone knowledgable to help me. As this is JavaScript and not Python, the results are not effected as white space isn't a problem. Thanks for the advice.


#5

Ok, sorry did'nt mean it to be rude. Would have been easier to follow though without pasting it into a readable form


#6

Remove the toUpperCase()
Why did you put that in anyway ??


#7

I know you weren't being rude. :disappointed_relieved:
The to upper and to lower case options were in the instructions in the previous exercise. I think it was presented as an option rather than compulsory but that part got through okay previously so I think that wasn't the problem in this exercise. The code seemed to work okay to the end but for some reason skipped the if/else statements. I'll try removing it and see what happens and mess around with it on an editor.
Thanks