forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebuggingLogicErrors5.js
More file actions
40 lines (34 loc) · 1.09 KB
/
Copy pathDebuggingLogicErrors5.js
File metadata and controls
40 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// The value of launchReady assigned in the first if/else block gets changed in the second if/else block. Dangerous waters...
// Since the issue is with launchReady, ONE way to fix the logic error is to use a different variable to store the fuel check result.
// Refactor the code to do this. Verify that your change works by updating the console.log statements.
let launchReady = false;
let fuelLevel = 18000;
let crewStatus = true;
let computerStatus = 'green';
let fuelReady = false;
let crewReady = false;
if (fuelLevel >= 20000) {
console.log('Fuel level cleared.');
fuelReady = true;
} else {
console.log('WARNING: Insufficient fuel!');
fuelReady = false;
}
if (crewStatus && computerStatus === 'green'){
console.log('Crew & computer cleared.');
crewReady = true;
} else {
console.log('WARNING: Crew or computer not ready!');
crewReady = false;
}
if (fuelReady && crewReady){
launchReady = true;
}else{
launchReady = false;
}
if (launchReady) {
console.log('10, 9, 8, 7, 6, 5, 4, 3, 2, 1...');
console.log('Liftoff!');
} else {
console.log('Launch scrubbed.');
}