marian74

1.Google Searches

Jun 2nd, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function googleSearch(arr) {
  2.     let days = Number(arr.shift());
  3.     let users = Number(arr.shift());
  4.     let moneyForSingleSearch = Number(arr.shift());
  5.     let moneyForDay = 0;
  6.    
  7.    
  8.     for (let i = 1; i <= users; i++) {
  9.         let words = Number(arr.shift());
  10.         let moneyForDayForUser = 0;
  11.         if (words === 1 ) {
  12.             moneyForDayForUser += moneyForSingleSearch * 2 ;
  13.         } else if (words < 5) {
  14.             moneyForDayForUser += moneyForSingleSearch * words;
  15.         }
  16.         if (i % 3 === 0) {
  17.             moneyForDayForUser = moneyForDayForUser * 3;
  18.         }
  19.         moneyForDay += moneyForDayForUser;
  20.        
  21.        
  22.     }
  23.     let allMoney = moneyForDay * days;
  24.     console.log(`Total money earned for ${days} days: ${allMoney.toFixed(2)}`);
  25. }
  26. googleSearch([10, 3, 6, 5, 4, 1 ])
Add Comment
Please, Sign In to add comment