Choose Your Own Adventure 2 !

I Choosing with Switch, And, & Or

i. What you’ll be building 1/6
Save and Submit

ii. Prompt 2/6

var user = prompt("What's your name?");

iii. .toUpperCase() and .toLowerCase() 3/6

var user = prompt("What's your name?").toUpperCase();

iv. Switch 4/6

var user = prompt("What's your name?").toUpperCase();
switch(user) {
    case 'SUNAKSHI':
        console.log("Oh! that's me!");
        break;
    case 'SAKSHAM':
        console.log("Hi Saksham!");
        break;
    case 'SANCHIT':
        console.log("You are the doc!");
        break;
    default:
        console.log("Welcome guest!");
}

v. Logical operators 5/6

var user = prompt("What's your name?").toUpperCase();
var surname = true;
var middlename = true;
switch(user) {
    case 'SUNAKSHI':
        if (surname && middlename) {
            console.log("Oh! that's me!");
        }
        else {
            console.log("Oh! that's still me!");
        }
        break;
    case 'SAKSHAM':
        if (surname || middlename) {
            console.log("Hi Saksham!");
        }
        else {
            console.log("Hi brother");
        }
        break;
        
        break;
    case 'SANCHIT':
        console.log("You are the doc!");
        break;
    default:
        console.log("Welcome guest!");
}

vi. You did it! 6/6
Save and Submit!

Advertisements

3 thoughts on “Choose Your Own Adventure 2 !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s