Advertisement
BbJLeB

Fishing NaN

Nov 22nd, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fishing(input) {
  2.     let limit = Number(input.shift());
  3.     let moneyWon = 0;
  4.     let moneyLost = 0;
  5.     let ch = "";
  6.     let fishesCounter = -1;
  7.     let moneyLeft = 0;
  8.     for (let i = 1; i <= limit + 1; i++) {
  9.         let name = String(input.shift());
  10.         if (name == "Stop"){
  11.             break;
  12.         }        
  13.         fishesCounter += 1;
  14.         let weight = input.shift();
  15.         let currentPrice = 0;
  16.         for (let i = 0; i < name.length; i++ ){
  17.             ch = name;
  18.             currentPrice += ch.charCodeAt(i);
  19.         }
  20.         currentPrice /= weight;
  21.         if (i % 3 == 0) {
  22.             moneyWon += currentPrice;
  23.         }else{
  24.             moneyLost += currentPrice;
  25.         }
  26.     }
  27.     if (fishesCounter == limit){
  28.         console.log(`Lyubo fulfilled the quota!`);
  29.     }
  30.     moneyLeft = (moneyWon-moneyLost);
  31.     if (moneyLeft < 0) {
  32.         console.log(`Lyubo lost ${Math.abs(moneyLeft.toFixed(2))} leva today.`);
  33.     } else {
  34.         console.log(`Lyubo's profit from ${fishesCounter} fishes is ${moneyLeft.toFixed(2)} leva.`);
  35.    }
  36.    
  37.  
  38. }
  39. fishing([ '3', 'catfish', '70', 'carp', '20', 'tench', '14' ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement