-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_conditional.js
55 lines (52 loc) · 1.2 KB
/
2_conditional.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ***** if ... else if ... else Statement*****
// Logic of checking the account balance at an ATM
let checkBalance = true;
let isActive = true;
let balance = 325.0;
console.log(
`isActive=${isActive}, balance=${balance}, checkBalance=${checkBalance}`
);
if (checkBalance) {
if (isActive && balance > 0) {
console.log(`Your balance is $${balance.toFixed(2)}`);
} else if (!isActive) {
console.log('Your account is no longer active.');
} else if (balance === 0) {
console.log('Your account is empty');
} else {
console.log('Your balance is negative. Please contact the bank.');
}
} else {
console.log('Thank you. Have a nice day!');
}
console.log();
// ***** switch Statement *****
// Check the number of days for a specific month (not including leap year)
let month = 'Nov';
let days = null;
switch (month) {
case 'Jan':
case 'Mar':
case 'May':
case 'Jul':
case 'Aug':
case 'Oct':
case 'Dec':
days = 31;
break;
case 'Apr':
case 'Jun':
case 'Sep':
case 'Nov':
days = 30;
break;
case 'Feb':
days = 28;
break;
default:
console.log('Not a valid month!');
break;
}
if (days !== null) {
console.log(`There are ${days} days in ${month}.`);
}