-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
123 lines (110 loc) · 3.86 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Ryder Cook
// INF651 - Front End Web Development I
// 27 September 2021
/* Practice Assignment 3:
Complete this javascript file according to the individual instructions
given in the comments.
*** DO NOT CHANGE any of the code that you are not instructed to. */
// 1) Construct a basic IF statement that assigns "Informatics" to the
// myDept variable IF the value of myNumber is greater than 1.
// The variables are already declared.
// Do not change the existing code.
const question1 = (myNumber) => {
let myDept;
/////// write your IF statement below this line /////////
if (myNumber > 1) {
myDept = "Informatics";
}
/////// write your IF statement above this line /////////
return myDept;
};
console.log(question1(myNumber = 5));
console.log(question1(myNumber = 1));
// 2) Construct an IF statement that assigns "JavaScript" to the
// myLang variable IF the length property of myValue is equal to 10.
// Add an ELSE statement that assigns "Python" otherwise.
// The variables are already declared.
// Do not change the existing code.
const question2 = (myValue) => {
let myLang;
/////// write your IF statement below this line /////////
if (myValue == 10) {
myLang = "JavaScript";
} else {
myLang = "Python";
}
/////// write your IF statement above this line /////////
return myLang;
};
console.log(question2(myValue = 10));
console.log(question2(myValue = 2));
// 3) Copy the IF / ELSE statement from #2 and paste it below.
// Add an ELSE IF statement to it that checks if the length property of
// myValue is greater than 3. If true, assign "PHP" to myLang.
// The variables are already declared.
// Do not change the existing code.
const question3 = (myValue) => {
let myLang;
/////// write your IF statement below this line /////////
if (myValue == 10) {
myLang = "JavaScript";
} else if (myValue > 3) {
myLang = "PHP";
} else {
myLang = "Python";
}
/////// write your IF statement above this line /////////
return myLang;
};
console.log(question3(myValue = 10));
console.log(question3(myValue = 33));
console.log(question3(myValue = -12));
// 4) Construct a SWITCH statement that will assign the following values to the variable
// myFaveFood based on the value of myNumber the SWITCH statement receives:
// 1 = Pizza, 2 = Hamburger, 3 = Ice Cream, 4 = Sushi, Anything else = Pho
// The variables are already declared.
// Do not change the existing code.
const question4 = (myNumber) => {
let myFaveFood;
/////// write your SWITCH statement below this line /////////
switch(myNumber) {
case 1:
myFaveFood = "Pizza";
break;
case 2:
myFaveFood = "Hamburger";
break;
case 3:
myFaveFood = "Ice Cream";
break;
case 4:
myFaveFood = "Sushi";
break;
default:
myFaveFood = "Pho";
}
/////// write your SWITCH statement above this line /////////
return myFaveFood;
};
console.log(question4(myNumber = 1));
console.log(question4(myNumber = 2));
console.log(question4(myNumber = 3));
console.log(question4(myNumber = 4));
console.log(question4(myNumber = 5));
// 5) Construct a TERNARY statement with the ternary operator
// that checks if the variable myTemp is greater than or equal to 75.
// If true, assign the value "Great weather!" to the variable myWeather.
// If false, assign the value "Still cold." to the variable myWeather.
// This ternary operator statement should just be one line of code.
// The variables are already declared.
// Do not change the existing code.
const question5 = (myTemp) => {
let myWeather;
/////// write your TERNARY OPERATOR statement below this line /////////
myWeather = myTemp >= 75 ? "Great weather!" : "Still cold.";
/////// write your TERNARY OPERATOR statement above this line /////////
return myWeather;
};
console.log(question5(myWeather = 75));
console.log(question5(myWeather = 101));
console.log(question5(myWeather = 43));