Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function club(input) {
- let target = Number(input[0]);
- let coctail = input;
- let pricePerCoctail = 0;
- let totalPrice = 0;
- let pricePerOrder = 0;
- for(let i = 1; i < coctail.length; i++) {
- if(i % 2 === 1) {
- let eachCoctail = coctail[i];
- let coctailCount = Number(coctail[i+1]);
- if(eachCoctail !== "Party!") {
- pricePerCoctail = Number(eachCoctail.length);
- pricePerOrder = pricePerCoctail * coctailCount;
- if(pricePerOrder % 2 === 1) {
- pricePerOrder *= 0.75;
- }
- totalPrice += pricePerOrder;
- if(target <= totalPrice) {
- console.log(`Target acquired.`);
- console.log(`Club income - ${totalPrice.toFixed(2)} leva.`);
- }
- }
- else if(eachCoctail === "Party!") {
- console.log(`We need ${(target - totalPrice).toFixed(2)} leva more.`);
- console.log(`Club income - ${totalPrice.toFixed(2)} leva.`);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement