|
|
@@ -0,0 +1,44 @@ |
|
|
|
let input = require('readline-sync'); |
|
|
|
|
|
|
|
let fuelLevel = 0, numAstronauts = 0, altitude = 0; |
|
|
|
|
|
|
|
while(true) { |
|
|
|
fuelLevel = input.question('Enter the starting fuel level: '); |
|
|
|
if (fuelLevel > 5_000 && fuelLevel < 30_000 && !isNaN(fuelLevel)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log(fuelLevel); |
|
|
|
|
|
|
|
while(true) { |
|
|
|
numAstronauts = input.question('Enter the number of astronauts: '); |
|
|
|
numAstronauts = Number(numAstronauts) |
|
|
|
if (numAstronauts < 1) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (numAstronauts > 7) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (isNaN(numAstronauts)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!Number.isInteger(numAstronauts)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
while (fuelLevel - 100*numAstronauts >=0) { |
|
|
|
altitude+=50; |
|
|
|
fuelLevel -= 100*numAstronauts; |
|
|
|
} |
|
|
|
|
|
|
|
console.log(`fuellevel: ${fuelLevel}`); |
|
|
|
console.log(`altitude: ${altitude}`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log(numAstronauts); |