Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function suitcaseLoad1(input) {
- let planeCapacity = Number(input[0]);
- let index = 1;
- let command = input[1];
- index++;
- let suitcasesLoaded = 0;
- while (command !== "End") {
- let suitcase = Number(command);
- suitcasesLoaded++;
- if (suitcasesLoaded % 3 === 0) {
- suitcase += suitcase * 0.10;
- }
- planeCapacity -= suitcase;
- if (planeCapacity < 0) {
- suitcasesLoaded--;
- break;
- }
- command = input[index];
- index++;
- }
- if (planeCapacity > 0) {
- console.log("Congratulations! All suitcases are loaded!");
- } else {
- console.log("No more space!");
- }
- console.log(`Statistic: ${suitcasesLoaded} suitcases loaded.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment