Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function decoration(input) {
- let budget = Number(input.shift());
- let decorName = String(input.shift());
- while (decorName != 'Stop') {
- let currentDecor = 0;
- for (let i = 0; i < decorName.length; i++) {
- currentDecor += Number(decorName.charCodeAt(i));
- }
- budget -= currentDecor;
- if (budget >= 0) {
- console.log("Item successfully purchased!");
- } else {
- console.log("Not enough money!");
- break;
- }
- decorName = String(input.shift());
- }
- if (budget > 0) {
- console.log(`Money left: ${budget}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment