Skip to content

Commit 4df2c4f

Browse files
committed
Chapter 5 Exercises
1 parent a0c2fbc commit 4df2c4f

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Declare and initialize the variables for exercise 1 here:
22

3+
let engineIndicatorLight = "red blinking";
4+
let spaceSuitsOn = true;
5+
let shuttleCabinReady = true;
6+
let crewStatus = spaceSuitsOn && shuttleCabinReady;
7+
let computerStatusCode = 200;
8+
let shuttleSpeed = 15000;
9+
310
// BEFORE running the code, predict what will be printed to the console by the following statements:
411

512
if (engineIndicatorLight === "green") {

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,33 @@ let shuttleSpeed = 15000;
99

1010
// a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready".
1111

12+
if (crewStatus === true) {
13+
console.log("Crew Ready");
14+
}
15+
else {
16+
console.log("Crew Not Ready");
17+
}
1218

1319
// 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!"
1420

21+
if (computerStatusCode === 200) {
22+
console.log("Please stand by. Computer is rebooting.");
23+
} else if (computerStatusCode === 400) {
24+
console.log("Success! Computer online.");
25+
} else {
26+
console.log("ALERT: Computer offline!");
27+
}
1528

1629
// 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".
1730

31+
if (shuttleSpeed > 17500) {
32+
console.log("ALERT: Escape velocity reached!");
33+
} else if (shuttleSpeed < 8000) {
34+
console.log("ALERT: Cannot maintain orbit!");
35+
} else {
36+
console.log("Stable speed");
37+
}
1838

1939
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
2040

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

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let engineIndicatorLight = 'red blinking';
2-
let fuelLevel = 21000;
1+
let engineIndicatorLight = 'NOT red blinking';
2+
let fuelLevel = 5000;
33
let engineTemperature = 1200;
44

55
/* 5) Implement the following checks using if/else if/else statements:
@@ -18,7 +18,25 @@ f) Otherwise, print "Fuel and engine status pending..." */
1818

1919
// Code 5a - 5f here:
2020

21+
if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === 'red blinking'){
22+
console.log("ENGINE FAILURE EMINENT!")
23+
} else if (fuelLevel <= 5000 || engineTemperature > 2500) {
24+
console.log("Check fuel level. Engines running hot.");
25+
} else if (fuelLevel > 20000 && engineTemperature <= 2500) {
26+
console.log("Full tank. Engines good.");
27+
} else if (fuelLevel > 10000 && engineTemperature <= 2500) {
28+
console.log("Fuel level above 50%. Engines good.");
29+
} else if (fuelLevel > 5000 && engineTemperature <= 2500) {
30+
console.log("Fuel level above 25%. Engines good.");
31+
} else console.log("Fuel and engine status pending...");
32+
2133
// 6) a) Create the variable commandOverride, and set it to be true or false. If commandOverride is false, then the shuttle should only launch if the fuel and engine check are OK. If commandOverride is true, then the shuttle will launch regardless of the fuel and engine status.
2234

35+
let commandOverride = false
36+
2337
/* 6) b) Code the following if/else check:
2438
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
39+
40+
if ((fuelLevel > 20000) && (engineIndicatorLight !== "red blinking") || (commandOverride = true)) {
41+
console.log("Cleared to launch!");
42+
} else console.log("Launch scrubbed!");

0 commit comments

Comments
 (0)