SHOW:
|
|
- or go back to the newest paste.
1 | function whileDemo(input) { | |
2 | ||
3 | let w = Number(input[0]); | |
4 | let l = Number(input[1]); | |
5 | let h = Number(input[2]); | |
6 | ||
7 | let freeSpace = w * l * h; | |
8 | let index = 3; | |
9 | let command = input[index]; | |
10 | ||
11 | while (command !== 'Done') { | |
12 | let numberOfBoxes = Number(command); | |
13 | freeSpace -= numberOfBoxes; | |
14 | if (freeSpace < 0) { | |
15 | console.log(`No more free space! You need ${Math.abs(freeSpace)} Cubic meters more.`); | |
16 | break; | |
17 | } | |
18 | index++; | |
19 | command = input[index]; | |
20 | } | |
21 | if (freeSpace >= 0) { | |
22 | console.log(`${freeSpace} Cubic meters left.`); | |
23 | } | |
24 | } |