You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

while.js 674B

123456789101112131415161718192021222324252627282930313233
  1. let input = require('readline-sync');
  2. let fuelLevel = 0;
  3. while (true) {
  4. fuelLevel = input.question('Enter starting fuel level: ');
  5. if (fuelLevel >5_000 && fuelLevel < 30_000){
  6. break;
  7. }
  8. }
  9. let numAstronauts;
  10. while(true) {
  11. numAstronauts = input.question('Enter the number of astronauts: ');
  12. numAstronauts = Number(numAstronauts);
  13. // dit is voor COMMAGETALLEN
  14. if (!Number.isInteger(numAstronauts)){
  15. continue; }
  16. if(numAstronauts >= 1 && numAstronauts <= 7){
  17. break;
  18. }
  19. }
  20. let altitude = 0;
  21. while(fuelLevel - 100 * numAstronauts >=0){
  22. altitude += 50;
  23. fuelLevel -= 100 * numAstronauts;
  24. }
  25. console.log(`Fuellevel ${fuelLevel}`)
  26. console.log(`altitude ${altitude}`)