Advertisement
PowerCell46

Salary task JS

Sep 30th, 2022 (edited)
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function payment(input) {
  2.     let numberOfOpenTabs = Number(input[0]);
  3.     let payment = Number(input[1]);
  4.  
  5.     let facebookBan = 150;
  6.     let instagramBan = 100;
  7.     let redditBan = 50;
  8.  
  9.     let facebookCounter = 0;
  10.     let instagramCounter = 0;
  11.     let redditCounter = 0;
  12.  
  13.     for(let tab = 2; tab <= numberOfOpenTabs + 1; tab++) {
  14.     let currentTab = input[tab];
  15.     if(currentTab === "Facebook") {
  16.     facebookCounter += 1;
  17.     } else if(currentTab === "Instagram") {
  18.     instagramCounter += 1;
  19.     } else if(currentTab === "Reddit") {
  20.     redditCounter += 1;
  21.     }
  22.     }
  23.  
  24.     let takenMoney = (facebookCounter * facebookBan) + (instagramCounter * instagramBan) + (redditCounter * redditBan);
  25.  
  26.     if(takenMoney >= payment) {
  27.         console.log("You have lost your salary.");
  28.     } else {
  29.     let finalMoney = payment - takenMoney;
  30.     console.log(finalMoney);
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement