My if statement isn't doing what I want it to do


#1

There are no error messages, but my code clearly isn't functioning properly. It doesn't matter what I put in my second prompt beneath the first case, the if statement doesn't matter or does not heed the response from the prompt. So, no matter what, I'll get the else response.

var user = prompt("Do you have a headache?").toUpperCase();
switch(user) {
    case 'YES':
        var headache = prompt("How bad is it?").toUpperCase();
        var migraine = prompt("Do you have a migraine?").toUpperCase();
        if (headache === 'BAD' && migraine ==='YES') {
            console.log("Take two ibuprofen and a bed day.");
        } else if (headache === 'SOMEWHAT' || headache === 'MILD') {
            console.log("Get some rest.");
        } else {
            console.log("Take care of yourself. Goodbye.")
        }
        break;
    case 'NO':
        console.log("Great!.");
        break;
    case 'MAYBE':
        console.log("Hmmm....");
        break
    default:
        console.log("It's a yes or no question...");
    break;
}

#2

I removed the else if statement and it worked. Also, the code I typed at headache twice in the else if statement which was incorrect, but it still would not have worked. I guess I don't understand how an else if statement would work in this context.


#3

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