## 01. Passion Days - Runtime error в Judge?

Задача 01. Дни за страстно пазаруване от 9.2.Problems for Champions - Part II от книгата JS Basics. Във VS-Code изходът е правилен, но в Judge дава Runtime error. Къде може да е грешката? Благодаря.

https://pastebin.com/h7zz0wbF
https://judge.softuni.org/Contests/Practice/Index/942#0
https://js-book.softuni.bg/chapter-09-problems-for-champions-part-2.html

Тагове:
0
Axiomatik 2422 Точки

Runtime error is triggered since Judge is expecting an array of arguments. Use console.log command in your submit to see the kind of input your program is receiving.

Still your code gives only 90%. Check out this earlier forum-discussion to find out where the last 10% are =>

``https://softuni.bg/forum/28839/9-2-passion-days-zadachi-za-shampioni-javascript``

;-)

Refactored code (90/100):

``````// function passionDays(shoppingMoney, commands) {
function passionDays(commands) {
shoppingMoney = Number(commands[0]);
let i = 1;
let purchases = 0;
let command = commands[i];

while (command !== 'mall.Enter') {
i++;
command = commands[i];
}

command = commands[++i];

while (command !== 'mall.Exit') {
for (let j = 0; j < command.length; j++) {
const action = command[j];

if (action >= 'A' && action <= 'Z') {
let price = action.charCodeAt() * 0.5;

if (shoppingMoney < price) {
continue;
}

shoppingMoney -= price;
purchases++;

} else if (action >= 'a' && action <= 'z') {
let price = action.charCodeAt() * 0.3;

if (shoppingMoney < price) {
continue;
}

shoppingMoney -= price;
purchases++;

} else if (action == '%') {
if (shoppingMoney > 0) {
shoppingMoney /= 2;
purchases++;
}

} else if (action == '*') {
shoppingMoney += 10;

} else {
let price = action.charCodeAt();

if (shoppingMoney < price) {
continue;
}

shoppingMoney -= price;
purchases++;
}
}

i++;
command = commands[i];
}

if (purchases === 0) {
console.log(`No purchases. Money left: \${shoppingMoney.toFixed(2)} lv.`);
} else {
console.log(`\${purchases} purchases. Money left: \${shoppingMoney.toFixed(2)} lv.`);
}
}``````

0
16/03/2022 14:00:39