Advertisement
PowerCell46

Trekking Mania JS

Oct 1st, 2022
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function trekking(input) {
  2.     let index = 0;
  3.     let numberOfGroups = input[index];
  4.     index++;
  5.     let allCounter = 0;
  6.     let musalaCounter = 0;
  7.     let monblanCounter = 0;
  8.     let kilimanjaroCounter = 0;
  9.     let k2Counter = 0;
  10.     let everestCounter = 0;
  11.  
  12.     for(let current = 0; current < numberOfGroups; current++) {
  13.         let membersOfTheCurrentGroup = Number(input[index]);
  14.         index++;
  15.        
  16.         allCounter += membersOfTheCurrentGroup
  17.  
  18.         if(membersOfTheCurrentGroup <= 5) {
  19.         musalaCounter+=membersOfTheCurrentGroup;
  20.         } else if( membersOfTheCurrentGroup >= 6 && membersOfTheCurrentGroup <=12) {
  21.         monblanCounter+= membersOfTheCurrentGroup;
  22.         } else if( membersOfTheCurrentGroup >= 12 && membersOfTheCurrentGroup <=25) {
  23.         kilimanjaroCounter+= membersOfTheCurrentGroup;
  24.         } else if( membersOfTheCurrentGroup >=26 && membersOfTheCurrentGroup <= 40) {
  25.         k2Counter+= membersOfTheCurrentGroup;
  26.         } else {
  27.         everestCounter+= membersOfTheCurrentGroup;
  28.         }
  29.     }
  30.  
  31. let musalaCounterAll = (musalaCounter / allCounter) * 100;
  32. let monblanCounterAll = (monblanCounter / allCounter) * 100;
  33. let kilimanjaroCounterAll = (kilimanjaroCounter / allCounter) * 100;
  34. let k2CounterAll = (k2Counter / allCounter) * 100;
  35. let everestCounterAll = (everestCounter / allCounter) * 100;
  36.    
  37. console.log(musalaCounterAll.toFixed(2) + "%");
  38. console.log(monblanCounterAll.toFixed(2) + "%");
  39. console.log(kilimanjaroCounterAll.toFixed(2) + "%");
  40. console.log(k2CounterAll.toFixed(2) + "%");
  41. console.log(everestCounterAll.toFixed(2) + "%");
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement