1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- let input = require('readline-sync');
-
- let fuelLevel = 7000;
- let astronauts = 1;
- let altitude_km = 50;
-
- // while (fuelLevel < 5000 || fuelLevel > 30_000) {
- // console.log("Enter starting fuel level:");
- // }
-
- // while (astronauts < 1 || astronauts > 7) {
- // console.log("Enter the number of astronauts");
- // }
-
- while (true) {
- fuelLevel = input.question('Enter starting fuel level:');
- fuelLevel = Number(fuelLevel);
- // anders wordt deze input als string geïnterpreteerd
- if (fuelLevel > 5_000 && fuelLevel < 30_000) {
- break;
- }
- }
-
- while (true) {
- astronauts = input.question('Enter number of astronauts:');
-
- astronauts = Number(astronauts);
- // anders wordt deze input als string geïnterpreteerd
-
- if (!Number.isInteger(astronauts)) {
- continu;
- }
- // als het nummer geen integer is (bv. hallo, kommagetal,...), wordt de loop verder uitgevoerd
-
- if (astronauts >= 1 && astronauts <= 7) {
- break;
- }
- }
-
- // while (fuelLevel > 100) {
- // fuelLevel -= 100;
- // altitude_km += 50;
- // if (fuelLevel < 100) {
- // break;
- // }
- // }
-
- while (fuelLevel - 100 * astronauts >= 0) {
- altitude_km += 50;
- fuelLevel -= 100 * astronauts;
- }
-
- console.log(`Fuel level: ${fuelLevel}`);
- console.log(`Altitude: ${altitude_km}`);
-
- if (fuelLevel === 100) {
- console.log("Fuel level is 100 units, impossible to increase altitude !")
- }
-
- if (fuelLevel > 5000 && fuelLevel > 30_000 && astronauts > 0 && astronauts < 7 && fuelLevel === 100) {
- console.log(`The shuttle gained an altitude of ${altitude_km} km.`);
- }
-
- if (altitude_km >= 2000) {
- console.log("Orbit achieved!");
- } else {
- console.log("Failed to reach orbit.");
- }
|