-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCh3-5.js
68 lines (59 loc) · 1.49 KB
/
Ch3-5.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
56
57
58
59
60
61
62
63
64
65
66
//ch3: following day
function excercise1(){
let input = prompt("Day of the week");
let whatDay = input.toString();
switch(whatDay){
case "Monday":
console.log("Tuesday");
break;
case "Tuesday":
console.log("Wednesday");
break;
case "Wednesday":
console.log("Thursday");
break;
case "Thursday":
console.log("Friday");
break;
case "Friday":
console.log("Saturday");
break;
case "Saturday":
console.log("Sunday");
break;
case "Sunday":
console.log("Monday");
break;
default:
console.log("Not a valid day.")
}
}
//ch 4: neither yes nor no
var doYoulikechickens = confirm("Are you sure you like chickens");
if (proceed) {
//proceed
} else {
//don't proceed
}
if (confirm('Are you sure you like chickens')) {
// true
console.log('good, have a chicken');
} else {
// false
console.log('thats what I thought')
}
//OR
let chickens= "yay"
if (chickens) {
console.log('Yay! I like chickens too');
} else {
console.log('BOO');
}
//ch 5: Calculator
const calculate = function(num1, num2) {
return num1 * num2;
};
console.log(calculate(4, "+", 6)); //must show 10
console.log(calculate(4, "-", 6)); //must show -2
console.log(calculate(4, "*", 6)); //must show 0
console.log(calculate(4, "/", 6)); //must show infinity