Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function club(input) {
- let wishedProfit = Number(input[0]);
- let index = 1;
- let command = input[index];
- index++;
- let drinksNumber = Number(input[index]);
- index++;
- let singlePrice = 0;
- let totalPrice = singlePrice * drinksNumber;
- let order = 0;
- while (command !== "Party!") {
- singlePrice = Number(command.length);
- totalPrice = singlePrice * drinksNumber;
- if (totalPrice % 2 !== 0) {
- totalPrice -= totalPrice * 0.25;
- }
- order += totalPrice;
- if (order >= wishedProfit) {
- console.log(`Target acquired.`);
- break;
- }
- command = input[index];
- index++;
- drinksNumber = Number(input[index]);
- index++;
- }
- if (command === "Party!") {
- console.log(`We need ${(wishedProfit - order).toFixed(2)} leva more.`);
- }
- console.log(`Club income - ${order.toFixed(2)} leva.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment