-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch.js
31 lines (26 loc) · 1.38 KB
/
switch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Let’s write a switch statement to decide what medal to award an athlete.
// athleteFinalPosition is already defined. 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.
let athleteFinalPosition = 'first place';
switch (athleteFinalPosition) {
case 'first place':
console.log('You get the gold medal!');
break;
case 'second place':
console.log('You get the silver medal!');
break;
case 'third place':
console.log('You get the bronze medal!');
break;
default:
console.log('No medal awarded.');
break;
}