Advertisement
RRusev77

Bike race

Mar 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(juniorCount, seniorCount, raceType) {
  2.     juniorCount = Number(juniorCount);
  3.     seniorCount = Number(seniorCount);
  4.     raceType = String(raceType);
  5.        
  6.     const allPrices = {
  7.             'trail': {
  8.                 'juniors': 5.5,
  9.                 'seniors': 7            
  10.             },
  11.  
  12.             'cross-country': {
  13.                 'juniors': 8,
  14.                 'seniors': 9.5    
  15.             },
  16.  
  17.             'downhill': {
  18.                 'juniors': 12.25,
  19.                 'seniors': 13.75    
  20.             },
  21.  
  22.             'road': {
  23.                 'juniors': 20,
  24.                 'seniors': 21.5  
  25.             }
  26.     };
  27.  
  28.     let juniorsPrice, seniorsPrice, overallPrice;
  29.  
  30.     juniorsPrice = allPrices[raceType].juniors * juniorCount;
  31.     seniorsPrice = allPrices[raceType].seniors * seniorCount;
  32.     overallPrice = juniorsPrice + seniorsPrice;
  33.  
  34.     if(raceType === 'cross-country' && (juniorCount + seniorCount) >= 50) {
  35.             overallPrice *= 0.75;
  36.     }
  37.  
  38.     overallPrice *= 0.95;
  39.     console.log(overallPrice.toFixed(2));
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement