Ivankooo1

Cinema

Jul 2nd, 2019
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. function Cinema(input){
  2. let vaucher = Number(input.shift());
  3. let price = 0;
  4. let buyProduct = 0;
  5. let buyTicket = 0;
  6.  
  7.  
  8. let command = input.shift();
  9. while(command !== 'End'){
  10.  
  11. if(command.length > 8){
  12. price = command.charCodeAt(0) + command.charCodeAt(1);
  13. if(price <= vaucher ){
  14. buyTicket++;
  15. vaucher -= price;
  16. }
  17. else{
  18. break;
  19. }
  20.  
  21. }
  22.  
  23.  
  24. if(command.length <= 8){
  25. price = command.charCodeAt(0);
  26. if(price <= vaucher){
  27. buyProduct++;
  28. vaucher -= price;
  29. }else{
  30. break;
  31. }
  32.  
  33. }
  34.  
  35. command = input.shift();
  36.  
  37. }
  38. console.log(buyTicket);
  39. console.log(buyProduct);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment