SHARE
TWEET

Untitled

a guest Apr 19th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function christmasDecoration(input) {
  2.     let buget = Number(input.shift());
  3.     let name = input.shift();
  4.  
  5.     let sum = 0;
  6.  
  7.     while (name != 'Stop') {
  8.         let price = 0
  9.         for (let i = 0; i < name.length; i++) {
  10.             price += name[i].charCodeAt()
  11.            
  12.         }
  13.        
  14.         if (price > buget - sum) {
  15.             console.log(`Not enough money!`);
  16.             break
  17.         } else {
  18.             console.log(`Item successfully purchased!`)
  19.             sum += price;
  20.             name = input.shift();
  21.         }
  22.  
  23.     }
  24.     let diff = buget - sum
  25.     if (name == 'Stop') {
  26.         console.log(`Money left: ${diff}`)
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top