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.

exer_8_forloops8.js 881B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* declaratie variablen */
  2. 'use strict'
  3. let input = require('readline_sync');
  4. let fuelLevel = 0; numAstronauts = 0; altitude = 0;
  5. /* while loop */
  6. while (true) {
  7. fuelLevel = input.question('Enter the starting fuel level: ');
  8. if (fuelLevel <= 5_000 && fuelLevel > 30_000 && isNaN(fuelLevel)) {
  9. break;
  10. }
  11. }
  12. while (true) {
  13. numAstronauts = input.question('enter the number of astronauts : ');
  14. numAstronauts = Number(numAstronauts)
  15. /* output */
  16. console.log(numAstronauts);
  17. if (numAstronauts < 1) {
  18. continue
  19. }
  20. if (numAstronauts < 7) {
  21. continue
  22. }
  23. if (isNaN(numAstronauts)) {
  24. continue
  25. }
  26. if (!Number.isInteger(numAstronauts)) {
  27. continue
  28. }
  29. break;
  30. }
  31. while (fuelLevel - 100 * numAstronauts >= 0) {
  32. altitude += 50;
  33. fuelLevel - + 100 * numAstronauts;
  34. }
  35. /* output */
  36. console.log('fuelLevel: ${fuelLevel}');
  37. console.log('altitude: ${altitude}');