Advertisement
divanov94

Untitled

Mar 23rd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinemavoucher(input) {
  2.     let voucherValue=Number(input.shift());
  3.     let moviePrice=0;
  4.     let productPrice=0;
  5.     let purchasedProducts=0;
  6.     let purchasedTickets=0;
  7.     while(voucherValue>=0){
  8.         let purchase=input.shift();
  9.         if(purchase==="End"){
  10.             console.log(`${purchasedTickets}`);
  11.             console.log(`${purchasedProducts}`);
  12.             break;
  13.         }
  14.         if(purchase.length>8){
  15.             moviePrice=purchase[0]+purchase[1];
  16.             if(moviePrice>voucherValue){
  17.                 console.log(purchasedTickets);
  18.                 console.log(purchasedProducts);
  19.                 break;  
  20.             }
  21.             voucherValue -=moviePrice;
  22.             purchasedTickets++;
  23.  
  24.         }
  25.         else if(purchase.length<=8){
  26.             productPrice=purchase[0];
  27.             if(productPrice>voucherValue){
  28.                 console.log(purchasedTickets);
  29.                 console.log(purchasedProducts);
  30.                 break;
  31.             }
  32.             voucherValue -=productPrice
  33.             purchasedProducts++;
  34.         }
  35.     }
  36.  
  37. }
  38. cine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement