Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function movieStars(input) {
- let index = 0;
- let budget = Number(input[index]);
- index++;
- let command = input[index];
- index++;
- let enoughMoney = true;
- while (command !== "ACTION") {
- if (command.length > 15) {
- let salary = budget * 0.2;
- if (budget - salary < 0) {
- enoughMoney = false;
- console.log(`We need ${(salary - budget).toFixed(2)} leva for our actors.`);
- break;
- }
- budget -= salary;
- } else if (command.length <= 15) {
- let currentSalary = Number(input[index]);
- index++;
- if (budget - currentSalary < 0) {
- enoughMoney = false;
- console.log(`We need ${(currentSalary - budget).toFixed(2)} leva for our actors.`);
- break;
- }
- budget -= currentSalary;
- }
- command = input[index];
- index++;
- }
- if (enoughMoney) {
- console.log(`We are left with ${budget.toFixed(2)} leva.`);
- }
- }
- movieStars(["90000", "Christian Bale", "70000.50", "Leonard DiCaprio", "Kevin Spacey", "24000.99"]);
- movieStars(["170000", "Ben Affleck", "40000.50", "Zahari Baharov", "80000", "Tom Hanks", "2000.99", "ACTION"]);
Add Comment
Please, Sign In to add comment