Skip to content

Commit 874f686

Browse files
committed
Booleans and conditionals exercise complete
1 parent c195ed6 commit 874f686

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
// Declare and initialize the variables for exercise 1 here:
2-
2+
let engineIndicatorLight = "red blinking";
3+
let spaceSuitsOn = true;
4+
let shuttleCabinReady = true;
5+
let crewStatus = spaceSuitsOn && shuttleCabinReady;
6+
let computerStatusCode = 200;
7+
let shuttleSpeed = 15000;
38
// BEFORE running the code, predict what will be printed to the console by the following statements:
49

510
if (engineIndicatorLight === "green") {
6-
console.log("engines have started");
11+
console.log("engines have started");
712
} else if (engineIndicatorLight === "green blinking") {
8-
console.log("engines are preparing to start");
13+
console.log("engines are preparing to start");
914
} else {
10-
console.log("engines are off");
15+
console.log("engines are off");
1116
}

booleans-and-conditionals/exercises/part-2.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,29 @@ let shuttleSpeed = 15000;
88
// 3) Write conditional expressions to satisfy the following safety rules:
99

1010
// a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready".
11-
11+
if (crewStatus) {
12+
console.log("Crew Ready");
13+
} else {
14+
console.log("Crew Not Ready");
15+
}
1216

1317
// b) If computerStatusCode is 200, print "Please stand by. Computer is rebooting." Else if computerStatusCode is 400, print "Success! Computer online." Else print "ALERT: Computer offline!"
14-
18+
if (computerStatusCode === 200) {
19+
console.log("Please stand by. Computer is rebooting.");
20+
} else if (computerStatusCode === 400) {
21+
console.log("Success! Computer online.");
22+
} else {
23+
console.log("ALERT: Computer offline!");
24+
}
1525

1626
// c) If shuttleSpeed is > 17,500, print "ALERT: Escape velocity reached!" Else if shuttleSpeed is < 8000, print "ALERT: Cannot maintain orbit!" Else print "Stable speed".
17-
18-
27+
if (shuttleSpeed > 17500) {
28+
console.log("ALERT: Escape velocity reached!");
29+
} else if (shuttleSpeed < 8000) {
30+
console.log("ALERT: Cannot maintain orbit!");
31+
} else {
32+
console.log("Stable speed.");
33+
}
1934
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
2035

21-
console.log(/* "Yes" or "No" */);
36+
console.log("Yes");

booleans-and-conditionals/exercises/part-3.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
let engineIndicatorLight = 'red blinking';
1+
let engineIndicatorLight = "red blinking";
22
let fuelLevel = 21000;
33
let engineTemperature = 1200;
44

5+
if (
6+
fuelLevel < 1000 ||
7+
engineTemperature > 3500 ||
8+
engineIndicatorLight === "red blinking"
9+
) {
10+
console.log("ENGINE FAILURE IMMINENT!");
11+
} else if (fuelLevel <= 5000 || engineTemperature > 2500) {
12+
console.log("Check fuel level. Engines running hot.");
13+
} else if (fuelLevel > 20000 && engineTemperature <= 2500) {
14+
console.log("Full tank. Engines good.");
15+
} else if (fuelLevel > 10000 && engineTemperature <= 2500) {
16+
console.log("Fuel level above 50%. Engines good.");
17+
} else if (fuelLevel > 5000 && engineTemperature <= 2500) {
18+
console.log("Fuel level above 25%. Engines good.");
19+
} else {
20+
console.log("Fuel and engine status pending...");
21+
}
22+
523
/* 5) Implement the following checks using if/else if/else statements:
624
725
a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good."
@@ -22,3 +40,9 @@ f) Otherwise, print "Fuel and engine status pending..." */
2240

2341
/* 6) b) Code the following if/else check:
2442
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
43+
let commandOverride = true;
44+
if ((fuelLevel > 20000 && engineIndicatorLight !== 'red blinking') || commandOverride) {
45+
console.log("Cleared to launch");
46+
} else {
47+
console.log("Launch scrubbed!");
48+
}

0 commit comments

Comments
 (0)