Skip to content

Commit a0ba33f

Browse files
committed
Space Shuttle Exercise
1 parent 1d1f55d commit a0ba33f

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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") {

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,34 @@ 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 == true) {
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-
27+
if (shuttleSpeed > 17500) {
28+
console.log("ALERT: Escape velocity reached!");
29+
} else if (computerStatusCode < 8000) {
30+
console.log("ALERT: Cannot maintain orbit!");
31+
} else {
32+
console.log("Stable speed");
33+
}
1834

1935
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
20-
21-
console.log(/* "Yes" or "No" */);
36+
if (!crewStatus || computerStatusCode !== 200 || !spaceSuitsOn) {
37+
console.log("WARNING. Not ready");
38+
} else {
39+
console.log("all systems go");
40+
}
41+
console.log("YESSSS!!!");

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,27 @@ e) If fuelLevel is below 1000 OR engineTemperature is above 3500 OR engineIndica
1717
f) Otherwise, print "Fuel and engine status pending..." */
1818

1919
// Code 5a - 5f here:
20-
20+
if (fuelLevel > 20000 && engineTemperature <= 2500){
21+
console.log("Full tank. Engines good.");
22+
} else if (fuelLevel > 10000 && engineTemperature <= 2500){
23+
console.log("Fuel level above 50%. Engines good");
24+
} else if (fuelLevel > 5000 && engineTemperature <= 2500){
25+
console.log("Fuel leve above 25%. Engines good.");
26+
} else if (fuelLevel <= 5000 || engineTemperature > 2500){
27+
console.log("Check fuel level. Engines running hot.");
28+
} else if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === "red blinking"){
29+
console.log("ENGINE FAILURE IMMINENT!");
30+
} else {console.log("Fuel and engine status pending...");
31+
}
2132
// 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.
33+
let commandOverride = true
34+
2235

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

0 commit comments

Comments
 (0)