Ivankooo1

Excursion

Aug 6th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Excursion(input){
  2.   let days = Number(input.shift());
  3.   let saveMoney = 0;
  4.   for(let i = 1;i<= days;i++){
  5.    let limit = 60;
  6.    let countProduct = 0;
  7.    let command = input.shift();
  8.    while(command !== 'Day over'){
  9.     let priceProduct = Number(command);
  10.     if(priceProduct > 60){
  11.       command = input.shift();
  12.       continue;
  13.      }
  14.  
  15.     limit += saveMoney;
  16.     limit -= priceProduct;
  17.     countProduct++;
  18.  
  19.     if(limit <= 0){
  20.        console.log(`Daily limit exceeded! You've bought ${countProduct} products.`);
  21.       break;
  22.      }
  23.          
  24.     command = input.shift();
  25.   }
  26.   if(limit > 0){
  27.    saveMoney = limit;
  28.    console.log(`Money left from today: ${saveMoney.toFixed(2)}.`);
  29.    console.log(`You've bought ${countProduct} products.`);
  30.   }
  31.   }
  32. }
  33.    Excursion([
  34.     3,
  35.     20,
  36.     40,
  37.     40,
  38.     15,
  39.     'Day over',
  40.     15,
  41.     5,
  42.     10,
  43.     17,
  44.     10,
  45.     'Day over'
  46.    
  47.    ]);
Advertisement
Add Comment
Please, Sign In to add comment