Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8b17d09

Browse files
author
bugagashenkj
committed
Add switch.js
1 parent d3e8d6f commit 8b17d09

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Javascript/6-switch.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const getDay = (n) => {
4+
switch (n) {
5+
case 1:
6+
return 'Monday';
7+
case 2:
8+
return 'Tuesday';
9+
case 3:
10+
return 'Wednesday';
11+
case 4:
12+
return 'Thursday';
13+
case 5:
14+
return 'Friday';
15+
case 6:
16+
return 'Saturday';
17+
case 7:
18+
return 'Sunday';
19+
default:
20+
return ('Invalid number!');
21+
}
22+
};
23+
24+
console.log(getDay(2));
25+
26+
27+
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday',
28+
'Friday', 'Saturday', 'Sunday'
29+
];
30+
31+
const getDayWithoutSwitch1 = (n) => (
32+
(n >= 1) && (n <= 7) ? days[n - 1] : 'Invalid number!'
33+
);
34+
35+
console.log(getDayWithoutSwitch1(2));

0 commit comments

Comments
 (0)