Skip to content

Commit c401379

Browse files
committed
finished assignment CH5
1 parent 824d987 commit c401379

File tree

3 files changed

+84
-14
lines changed

3 files changed

+84
-14
lines changed
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
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+
10+
11+
312
// BEFORE running the code, predict what will be printed to the console by the following statements:
413

514
if (engineIndicatorLight === "green") {
6-
console.log("engines have started");
7-
} else if (engineIndicatorLight === "green blinking") {
8-
console.log("engines are preparing to start");
9-
} else {
10-
console.log("engines are off");
11-
}
15+
console.log("engines have started");
16+
} else if (engineIndicatorLight === "green blinking") {
17+
console.log("engines are preparing to start");
18+
} else {
19+
console.log("engines are off");
20+
}
Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let engineIndicatorLight = "red blinking";
1+
let engineIndicatorLight = "red blinking";//THIS IS A STRING NOT A VARIABLE SO "" ARE ADDED
22
let spaceSuitsOn = true;
33
let shuttleCabinReady = true;
44
let crewStatus = spaceSuitsOn && shuttleCabinReady;
@@ -9,13 +9,53 @@ let shuttleSpeed = 15000;
99

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

12-
12+
if (crewStatus === true) {
13+
console.log("Crew Ready");// ; IS ON THIS LINE NOT AT THE FIRST LINE
14+
} else {
15+
console.log("Crew Not Ready");
16+
}
17+
/*
18+
if (crewStatus) { THIS IS ANOTHER WAY OF WRITING THE ABOVE STATEMENT BUT BOTH WAYS ARE CORRECT?
19+
console.log("Crew Ready");
20+
} else {
21+
console.log("Crew Not Ready");
22+
}
23+
*/
1324
// 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!"
1425

26+
if (computerStatusCode === 200) {
27+
console.log("Please stand by. Computer is rebooting");
28+
} else if (computerStatusCode === 400) {
29+
console.log("Success! Computer online.");
30+
} else {
31+
console.log("ALERT: Computer offline!");
32+
}
33+
1534

1635
// 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".
1736

1837

38+
if (shuttleSpeed > 17500) {
39+
console.log("ALERT: Escape velocity reached!");
40+
} else if (shuttleSpeed < 8000) {
41+
console.log("ALERT: Cannot maintain orbit!");
42+
} else {
43+
console.log("Stable speed");
44+
}
45+
1946
// 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result?
2047

21-
console.log(/* "Yes" or "No" */);
48+
/*COMPARE THESE TWO LOOPS TO PREDICT THE OUTCOME!
49+
if (crewStatus && computerStatusCode === 200 && spaceSuitsOn) {
50+
console.log("all systems go");
51+
} else {
52+
console.log("WARNING. Not ready");
53+
}
54+
if (!crewStatus || computerStatusCode !== 200 || !spaceSuitsOn) {
55+
console.log("WARNING. Not ready");
56+
} else {
57+
console.log("all systems go");
58+
}
59+
*/
60+
61+
console.log("No");
Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
11
let engineIndicatorLight = 'red blinking';
22
let fuelLevel = 21000;
33
let engineTemperature = 1200;
4+
let commandOverride = true;
5+
46

57
/* 5) Implement the following checks using if/else if/else statements:
68
7-
a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good."
9+
a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good."!
810
9-
b) If fuelLevel is above 10000 AND engineTemperature is at or below 2500, print "Fuel level above 50%. Engines good."
11+
b) If fuelLevel is above 10000 AND engineTemperature is at or below 2500, print "Fuel level above 50%. Engines good."!
1012
11-
c) If fuelLevel is above 5000 AND engineTemperature is at or below 2500, print "Fuel level above 25%. Engines good."
13+
c) If fuelLevel is above 5000 AND engineTemperature is at or below 2500, print "Fuel level above 25%. Engines good."!
1214
13-
d) If fuelLevel is at or below 5000 OR engineTemperature is above 2500, print "Check fuel level. Engines running hot."
15+
d) If fuelLevel is at or below 5000 OR engineTemperature is above 2500, print "Check fuel level. Engines running hot."!
1416
15-
e) If fuelLevel is below 1000 OR engineTemperature is above 3500 OR engineIndicatorLight is red blinking print "ENGINE FAILURE IMMINENT!"
17+
e) If fuelLevel is below 1000 OR engineTemperature is above 3500 OR engineIndicatorLight is red blinking print "ENGINE FAILURE IMMINENT!" !
1618
1719
f) Otherwise, print "Fuel and engine status pending..." */
1820

1921
// Code 5a - 5f here:
2022

23+
if (fuelLevel > 20000 && engineTemperature <= 2500) {
24+
console.log("Full tank. Engines good.");
25+
} else if (fuelLevel > 10000 && engineTemperature <= 2500) {
26+
console.log("Fuel level above 50%. Engines good.");
27+
} else if (fuelLevel > 5000 && engineTemperature <= 2500) {
28+
console.log("Fuel leve above 25%. Engines good.");
29+
} else if (fuelLevel <= 5000 || engineTemperature > 2500) {
30+
console.log("Check fuel level. Engines running hot.");
31+
} else if (fuelLevel < 1000 || engineTemperature > 3500 || engineIndicatorLight === 'red blinking') {
32+
console.log("ENGINE FAILURE IMMINENT!");
33+
} else {
34+
console.log("Fuel and engine status pending...");
35+
}
36+
2137
// 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.
2238

2339
/* 6) b) Code the following if/else check:
2440
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
41+
if (fuelLevel > 20000 && engineIndicatorLight !== 'red blinking' || commandOverride === true) {// alternatively !engineIndicatorLight could be used
42+
console.log("Cleared to launch!");
43+
} else {
44+
console.log("Launch scrubbed!")
45+
}

0 commit comments

Comments
 (0)