Successful Example of Nesting if Inside Switches


I just wanted to share an example of code that works.

var userShirt = prompt("What color is your shirt today?","say blue, tan, or white").toUpperCase()

switch (userShirt){
    case 'BLUE':
        var userEyes = prompt("What color are your eyes?","say blue, brown, or hazel").toUpperCase()
        if(userEyes === 'BROWN' || userEyes === 'HAZEL'){
            console.log("Your eyes don't match your shirt.");
        } else {
            console.log("Your eyes match your shirt!");
    case 'TAN':
        var userWatch = prompt("Do you have a watch on?","say yes or no").toUpperCase()
        if(userShirt === 'TAN' && userWatch === 'YES'){
            console.log("Cool--your eyes match your watch!");
        } else {
            console.log("I guess you don't mind being late...");
    case 'WHITE':
        var userCap = prompt("Do you have a baseball cap on?","say yes or no").toUpperCase()
            console.log("Dude--a white shirt and a cap is the move!");
        } else {
            console.log("Rock on--that's a great combo!");
        console.log("Hrm... we're a bit lost here!")


Er if i'm not mistaken, we're not supposed to share answers, or rather give answers directly to help people get through the lesson, as it defeats the purpose of having the lessons in the first place.


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