選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

solution.js 881B

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