Спасибо за ответ! Появился еще 1 вопрос по более длинной задаче. В общем мне показали как решить ее с помощью input.shift(), но также очень бы хотелось понять, как она решается с помощью индексов. 2 часа бьюсь, уже запускала дебагер и вроде как ошибка идет со строки let command = Number(input[index]); Но не понимаю, что именно надо изменить. Вот весь код.
function demo(input) {
debugger;
let width = Number(input[0]);
let length = Number(input[1]);
let height = Number(input[2]);
let space = width * length * height;
let sum = 0;
let index = 2;
let command = Number(input[index]);
while (command !== "Done") {
let currentCubic = Number(command);
sum = sum + currentCubic;
if(space < sum){
console.log(`No more free space! You need ${sum - space} Cubic meters more.`);
break;
}
index++;
}
if(command === "Done") {
console.log(`${space-sum} Cubic meters left.`);
}
}
demo(["10",
"10",
"2",
"20",
"20",
"20",
"20",
"122"]);
|