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.

exercise_6.js 982B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. let startfuel = 0;
  2. let astronauts = 0;
  3. let altitude = 0;
  4. let input = require('readline-sync');
  5. while (true) {
  6. startfuel = input.question("Enter starting fuel level: ");
  7. if (startfuel >= 5_000 && startfuel < 30_000 && !isNaN(startfuel)) {
  8. break;
  9. }
  10. }
  11. while (true) {
  12. astronauts = input.question("Enter number of astronauts: ");
  13. astronauts = Number(astronauts);
  14. if (astronauts > 0 && astronauts <= 7 && !isNaN(astronauts) && Number.isInteger(Number(astronauts))) {
  15. break;
  16. }
  17. }
  18. /*
  19. // ook mogelijk
  20. while (true) {
  21. astronauts = input.question("Enter number of astronauts: ");
  22. astronauts = Number(astronauts);
  23. if (astronauts < 0) {
  24. continue;
  25. }
  26. if (astronauts > 7)){
  27. continue;
  28. }
  29. if (isNaN(astronauts)){
  30. continue;
  31. }
  32. if (Number.isInteger(Number(astronauts)){
  33. continue;
  34. }
  35. break;
  36. }
  37. */
  38. while (startfuel - 100 * astronauts >= 0) {
  39. altitude += 50;
  40. startfuel -= 100 * astronauts;
  41. }
  42. console.log(`fuellevel: ${startfuel}`);
  43. console.log(`astronauts ${astronauts}`);