|
|
@@ -0,0 +1,26 @@ |
|
|
|
const input = require('readline-sync'); |
|
|
|
|
|
|
|
let fuelLevel = 0, numAstronauts = 0, altitude = 0; |
|
|
|
|
|
|
|
while (fuelLevel <= 5000 || fuelLevel >= 30_000 || isNaN(fuelLevel)) { |
|
|
|
fuelLevel = input.question('Enter the starting fuel level: ') |
|
|
|
} |
|
|
|
|
|
|
|
console.log('Starting fuel level: ' + fuelLevel); |
|
|
|
|
|
|
|
while (numAstronauts < 1 || numAstronauts > 7 || isNaN(numAstronauts)) { |
|
|
|
numAstronauts = input.question("Enter the number of astronauts: ") |
|
|
|
} |
|
|
|
|
|
|
|
while (fuelLevel - 100 * numAstronauts >= 0) { |
|
|
|
altitude += 50; |
|
|
|
fuelLevel -= 100 * numAstronauts; |
|
|
|
} |
|
|
|
|
|
|
|
console.log('The shuttle gained an altitude of ' + altitude + ' km.'); |
|
|
|
|
|
|
|
if (altitude >= 2000) { |
|
|
|
console.log('Orbit achieved!'); |
|
|
|
} else { |
|
|
|
console.log('Failed to reach orbit.'); |
|
|
|
} |