Skip to content

Commit

Permalink
Exercises completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
craigb28 committed Jan 10, 2024
1 parent d206267 commit 30ddf24
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
6 changes: 6 additions & 0 deletions booleans-and-conditionals/exercises/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions booleans-and-conditionals/exercises/part-1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// Declare and initialize the variables for exercise 1 here:

let engineIndicatorLight = "red blinking"
let spaceSuitsOn = true
let shuttleCabinReady = true
let crewStatus = spaceSuitsOn && shuttleCabinReady
let computerStatusCode = 200
let shuttleSpeed = 15000

// BEFORE running the code, predict what will be printed to the console by the following statements:

if (engineIndicatorLight === "green") {
Expand Down
40 changes: 38 additions & 2 deletions booleans-and-conditionals/exercises/part-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,50 @@ let shuttleSpeed = 15000;
// 3) Write conditional expressions to satisfy the following safety rules:

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

if (crewStatus === true) {
console.log ("Crew Ready")
} else {
console.log("Crew Not Ready");
}

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

if (computerStatusCode === 200) {
console.log("Please stand by. Computer is rebooting.");
} else if (computerStatusCode === 400) {
console.log ("Success! Computer online.");
} else {
console.log("ALERT: Computer offline!");
}

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

if (shuttleSpeed > 17500) {
console.log("ALERT: escape velocity reached!");
} else if (shuttleSpeed < 8000) {
console.log("ALERT: Cannot maintain orbit!");
} else {
console.log("Stable speed");
}

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

console.log(/* "Yes" or "No" */);
// Prediction is:


console.log("No");

if (crewStatus && computerStatusCode === 200 && spaceSuitsOn) {
console.log("all systems go");
} else {
console.log("WARNING. Not ready");
}

if (!crewStatus || computerStatusCode !== 200 || !spaceSuitsOn) {
console.log("WARNING. Not ready");
} else {
console.log("all systems go");
}

// Because all three parts of the compound boolean are false in the second one,
//then it doesn't execute the "if" code", and then moves on to the "else" code
49 changes: 45 additions & 4 deletions booleans-and-conditionals/exercises/part-3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let engineIndicatorLight = 'red blinking';
let fuelLevel = 21000;
let engineTemperature = 1200;
let engineIndicatorLight = !'red blinking';
let fuelLevel = 18000;
let engineTemperature = 2500;

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

// Code 5a - 5f here:

if (fuelLevel<1000 || engineTemperature>3500 || engineIndicatorLight === "red blinking"){
console.log ("ENGINE FAILURE IMMINENT!")
} else if (fuelLevel<= 5000 || engineTemperature>2500) {
console.log("Check fuel level. Engines running hot.")
} else if (fuelLevel > 20000 && engineTemperature <= 2500) {
console.log("Full tank. Engines good.")
} else if (fuelLevel>10000 && engineTemperature<= 2500) {
console.log("Fuel level above 50%. Engines good.")
} else if (fuelLevel>5000 && engineTemperature <= 2500) {
console.log("Fuel level above 25%. Engines good.")
} else {
console.log("Fuel and engine status pending.")
}
// 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.

let commandOverride = true || false

if (commandOverride == false){
if (fuelLevel>5000 && engineTemperature<=2500){
console.log("Cleared to launch!")
} else {
console.log("NOT clear for launch. Remain grounded.")
}
} else if (commandOverride == true){
console.log("Cleared to launch!")
}


/* 6) b) Code the following if/else check:
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
If fuelLevel is above 20000
AND engineIndicatorLight is NOT red blinking
OR commandOverride is true
print "Cleared to launch!" Else print "Launch scrubbed!" */

if (fuelLevel>20000 && engineIndicatorLight != "red blinking"){
console.log("Cleared to launch!")
} else if (commandOverride=true){
console.log("Cleared to launch!")
} else {
console.log("Launch scrubbed!")
}




0 comments on commit 30ddf24

Please sign in to comment.