Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fishing(input) {
- let limit = Number(input.shift());
- let moneyWon = 0;
- let moneyLost = 0;
- let ch = "";
- let fishesCounter = -1;
- let moneyLeft = 0;
- for (let i = 1; i <= limit + 1; i++) {
- let name = String(input.shift());
- if (name == "Stop"){
- break;
- }
- fishesCounter += 1;
- let weight = input.shift();
- let currentPrice = 0;
- for (let i = 0; i < name.length; i++ ){
- ch = name;
- currentPrice += ch.charCodeAt(i);
- }
- currentPrice /= weight;
- if (i % 3 == 0) {
- moneyWon += currentPrice;
- }else{
- moneyLost += currentPrice;
- }
- }
- if (fishesCounter == limit){
- console.log(`Lyubo fulfilled the quota!`);
- }
- moneyLeft = (moneyWon-moneyLost);
- if (moneyLeft < 0) {
- console.log(`Lyubo lost ${Math.abs(moneyLeft.toFixed(2))} leva today.`);
- } else {
- console.log(`Lyubo's profit from ${fishesCounter} fishes is ${moneyLeft.toFixed(2)} leva.`);
- }
- }
- fishing([ '3', 'catfish', '70', 'carp', '20', 'tench', '14' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement