Bart Van Roy 2 лет назад
Родитель
Сommit
23c9d6e4c0
1 измененных файлов: 26 добавлений и 0 удалений
  1. 26
    0
      loops/oefening4.js

+ 26
- 0
loops/oefening4.js Просмотреть файл

@@ -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.');
}

Загрузка…
Отмена
Сохранить