Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function passionDays(input) {
- let budget = Number(input.shift());
- let command = input.shift();
- let counter = 0;
- let isNoShopping = false;
- if (command === "mall.Enter") {
- command = input.shift();
- while (command !== "mall.Exit") {
- for (let i = 0; i < command.length; i++) {
- if (command.charCodeAt(i) >= 65 && command.charCodeAt(i) <= 90) {
- if (command.charCodeAt(i) / 2 > budget) {
- isNoShopping = true;
- break;
- }
- budget = budget - command.charCodeAt(i) / 2;
- } else if (
- command.charCodeAt(i) >= 97 &&
- command.charCodeAt(i) <= 122
- ) {
- if (command.charCodeAt(i) * 0.3 > budget) {
- isNoShopping = true;
- break;
- }
- budget -= command.charCodeAt(i) * 0.3;
- } else if (command[i] === "%") {
- if (command.charCodeAt(i) > budget) {
- isNoShopping = true;
- break;
- }
- budget = budget / 2;
- } else if (command[i] === "*") {
- budget += 10;
- } else {
- if (command.charCodeAt(i) > budget) {
- isNoShopping = true;
- break;
- }
- budget -= command.charCodeAt(i);
- }
- }
- if (isNoShopping === true) {
- break;
- }
- counter++;
- command = input.shift();
- }
- }
- if (counter === 0) {
- console.log(`No purchases. Money left: ${budget.toFixed(2)} lv.`);
- } else if (counter > 0) {
- console.log(`${counter} purchases. Money left: ${budget.toFixed(2)} lv.`);
- }
- }
- passionDays([110, "mall.Enter", "%", "a", "b", "a", "mall.Exit"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement