Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cinemavoucher(input) {
- let voucherValue=Number(input.shift());
- let moviePrice=0;
- let productPrice=0;
- let purchasedProducts=0;
- let purchasedTickets=0;
- while(voucherValue>=0){
- let purchase=input.shift();
- if(purchase==="End"){
- console.log(`${purchasedTickets}`);
- console.log(`${purchasedProducts}`);
- break;
- }
- if(purchase.length>8){
- moviePrice=purchase[0]+purchase[1];
- if(moviePrice>voucherValue){
- console.log(purchasedTickets);
- console.log(purchasedProducts);
- break;
- }
- voucherValue -=moviePrice;
- purchasedTickets++;
- }
- else if(purchase.length<=8){
- productPrice=purchase[0];
- if(productPrice>voucherValue){
- console.log(purchasedTickets);
- console.log(purchasedProducts);
- break;
- }
- voucherValue -=productPrice
- purchasedProducts++;
- }
- }
- }
- cine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement