Essential Question: How can I create a select case statement in JavaScript?
Mastery Objectives:
SWBAT create select case statements in JavaScript.
SWBAT add images to their web pages using JavaScript.
Do Now: Write a JavaScript program to capitalize the first letter of each word of a given string.
Resources: https://app.nearpod.com/?pin=4E3L6 - Nearpod on switch statements.
Directions: Type out the projects below.
Switch statements need to be the same datatype in order to work.
let athleteFinalPosition = 'first place';
Let’s write a switch statement to decide what medal to award an athlete.
athleteFinalPosition is already defined at the top of main.js. So start by writing a switch statement with athleteFinalPosition as its expression.
Inside the switch statement, add three cases:
The first case checks for the value 'first place' If the expression’s value matches the value of the case then console.log() the string 'You get the gold medal!'
The second case checks for the value 'second place' If the expression’s value matches the value of the case then console.log() the string 'You get the silver medal!'
The third case checks for the value 'third place' If the expression’s value matches the value of the case then console.log() the string 'You get the bronze medal!'
Remember to add a break after each console.log().
Now, add a default statement at the end of the switch that uses console.log() to print 'No medal awarded.'.
If athleteFinalPosition does not equal any value of our cases, then the string 'No medal awarded.' is logged to the console.
Remember to add the break keyword at the end of the default case.
Create a switch statement that will alert "Hello" if fruits is "banana", and "Welcome" if fruits is "apple".