-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathConditionsAndLoops-Solution.js
More file actions
144 lines (120 loc) · 3.44 KB
/
ConditionsAndLoops-Solution.js
File metadata and controls
144 lines (120 loc) · 3.44 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Copyright (c) 2023 Promineo Tech
// Author: Promineo Tech Academic Team
// Subject: Conditions & Loops Lab
// JavaScript Week 02 Lab
//
// create a variable called speedLimit and another called mySpeed
// set their values to numbers between 1 and 100
let speedLimit = 50;
let mySpeed = 65;
// using a conditional, determine if mySpeed is greater than the speedLimit
// if true, print "Slow Down! Mom is mad!" to the console
// if mySpeed is equal to the speedLimit, print "Everyone is happy!" to the console
// if mySpeed is less than the speedLimit, print "Speed up! Dad is mad!"
if(mySpeed > speedLimit){
console.log("Slow Down! Mom is mad!")
} else if(mySpeed == speedLimit){
console.log("Everyone is happy!")
} else {
console.log("Speed up! Dad is mad!")
}
// create two variables, one named alarmSet, the other openDoor
// set them to a boolean value
let alarmSet = true;
let openDoor = false;
// using a conditional, determine if alarm is set.
// if alarm is set and door is set to open, print "Sound Alarm!" to the console
// otherwise, print "Everything is fine." to the console.
if(alarmSet && openDoor) {
console.log("Sound Alarm!")
} else {
console.log("Everything is fine.")
}
// create two variables, username and password
// create a conditional, if the username is "Tommy123" and the password is "12345"
// or the username is "Timmy456" and the password is "6789", print "Admin Login Successful" to the console
// otherwise, print "Admin Access Denied"
let username = "Tommy123";
let password = "12345";
if((username === "Tommy123" && password === "12345") || (username === "Timmy456" && password === "6789")){
console.log("Admin Login Successful");
} else {
console.log("Admin Access Denied");
}
// write code that will set the value of studentClass based on studentGrade
// studentGrade will be K-12
// K-6 will be Elementary
// 7-8 will be Middle
// 9 will be Freshman, 10 Sophomore, 11 Junior, 12 Senior
// Anything other than these values will print "Error" to the console
let studentGrade = 13;
let studentClass;
switch(studentGrade){
case 'K':
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
studentClass = "Elementary";
break;
case 7:
case 8:
studentClass = "Middle";
break;
case 9:
studentClass = "Freshman";
break;
case 10:
studentClass = "Sophomore";
break;
case 11:
studentClass = "Junior";
break;
case 12:
studentClass = "Senior";
break;
default:
console.log("Error");
}
console.log(studentClass);
// write a for loop that will iterate backwards from 10 to -10
for(let i = 10; i >= -10; i--){
console.log(i);
}
// write a do/while loop that prints 1 through 50
let iterator = 1;
do {
console.log(iterator);
iterator++;
} while(iterator <= 50);
// edit the previous do/while loop so that it prints only numbers divisible by 4
iterator = 1;
do {
if(iterator % 4 == 0){
console.log(iterator);
}
iterator++;
} while(iterator <= 50);
// Someone messed up the following for loop
// fix the following infinite loop, uncomment to test
/*
for(let i = 110; i > 10; i++){
console.log(i);
}
*/
// depends what we need the loop to do
//prints 1-9
for(let i = 1; i < 10; i++){
console.log(i);
}
//prints 11-99
for(let i = 11; i < 100; i++){
console.log(i);
}
//prints 110-11
for(let i = 110; i > 10; i--){
console.log(i);
}