-Enigmos-

movieStars.js

Nov 29th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function movieStars(input) {
  2.     let index = 0;
  3.     let budget = Number(input[index]);
  4.     index++;
  5.     let command = input[index];
  6.     index++;
  7.     let enoughMoney = true;
  8.  
  9.     while (command !== "ACTION") {
  10.         if (command.length > 15) {
  11.             let salary = budget * 0.2;
  12.  
  13.             if (budget - salary < 0) {
  14.                 enoughMoney = false;
  15.                 console.log(`We need ${(salary - budget).toFixed(2)} leva for our actors.`);
  16.                 break;
  17.             }
  18.             budget -= salary;
  19.         } else if (command.length <= 15) {
  20.             let currentSalary = Number(input[index]);
  21.             index++;
  22.            
  23.             if (budget - currentSalary < 0) {
  24.                 enoughMoney = false;
  25.                 console.log(`We need ${(currentSalary - budget).toFixed(2)} leva for our actors.`);
  26.                 break;
  27.             }
  28.             budget -= currentSalary;
  29.         }
  30.  
  31.         command = input[index];
  32.         index++;
  33.     }
  34.     if (enoughMoney) {
  35.         console.log(`We are left with ${budget.toFixed(2)} leva.`);
  36.     }
  37. }
  38.  
  39. movieStars(["90000", "Christian Bale", "70000.50", "Leonard DiCaprio", "Kevin Spacey", "24000.99"]);
  40. movieStars(["170000", "Ben Affleck", "40000.50", "Zahari Baharov", "80000", "Tom Hanks", "2000.99", "ACTION"]);
Add Comment
Please, Sign In to add comment