Todorov_Stanimir

01. Christmas Spirit Tech Fund Mid Exam - 18 December 2018

May 28th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function christmasspirit(input) {
  2.     let quantity = parseInt(input[0]);
  3.     let days = parseInt(input[1]);
  4.  
  5.     let totalCost = 0;
  6.     let totalSpirit = 0;
  7.     let priceOrnamentSet = 2;
  8.     let priceTreeSkirt = 5;
  9.     let priceTreeGarlands = 3;
  10.     let priceTreeLight = 15;
  11.  
  12.     for (let i = 1; i <= days; i++) {
  13.         if (i % 11 === 0) {
  14.             quantity += 2;
  15.         }
  16.         if (i % 2 === 0) {
  17.             totalCost += quantity * priceOrnamentSet;
  18.             totalSpirit += 5;
  19.         }
  20.         if (i % 3 === 0) {
  21.             totalCost += quantity * (priceTreeSkirt + priceTreeGarlands);
  22.             totalSpirit += 13;
  23.         }
  24.         if (i % 5 === 0) {
  25.             totalCost += quantity * priceTreeLight;
  26.             totalSpirit += 17;
  27.         }
  28.         if (i % 3 === 0 && i % 5 === 0) {
  29.             totalSpirit += 30;
  30.         }
  31.         if (i % 10 === 0) {
  32.             totalSpirit -= 20;
  33.             totalCost += 1 * (priceTreeSkirt + priceTreeGarlands + priceTreeLight);
  34.         }
  35.     }
  36.     if (days % 10===0) {
  37.         totalSpirit -= 30;
  38.     }
  39.     console.log(`Total cost: ${totalCost}`);
  40.     console.log(`Total spirit: ${totalSpirit}`);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment