Advertisement
Liliana797979

vqrno reshenie na club

Dec 27th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.  
  3. let target = Number(input[0]);
  4.  
  5. // let cocktailName = input[1];
  6.  
  7. // let cocktailNum = parseInt(input[2]);
  8.  
  9. let index = 1;
  10.  
  11. let sum = 0;
  12.  
  13. // let cocktail = input;
  14.  
  15.  
  16.  
  17. while (index < input.length) {
  18.  
  19. let cocktailName = input[index];
  20.  
  21.  
  22.  
  23. if (cocktailName === "Party!") {
  24.  
  25. console.log(`We need ${(target - sum).toFixed(2)} leva more.`);
  26.  
  27. // console.log("We need " + Math.abs(target - sum).toFixed(2) + " leva more.");
  28.  
  29. break;
  30.  
  31. }
  32.  
  33. // let cocktailName = input[1];
  34.  
  35. let cocktailNum = Number(input[index + 1]);
  36.  
  37.  
  38.  
  39. let cocktailPrice = (cocktailName.length) * cocktailNum;
  40.  
  41.  
  42.  
  43. if (cocktailPrice % 2 !== 0) {
  44.  
  45. cocktailPrice *= 0.75;
  46.  
  47. }
  48.  
  49.  
  50.  
  51. sum += cocktailPrice;
  52.  
  53. index += 2;
  54.  
  55.  
  56.  
  57. if (sum >= target) {
  58.  
  59. // console.log("Target acquired");
  60.  
  61. // console.log("Club income " + sum.toFixed(2) + " leva.");
  62.  
  63. break;
  64.  
  65. }
  66.  
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73. if (sum < target) {
  74.  
  75. // console.log("We need " + Math.abs(target - sum).toFixed(2) + " leva more.");
  76.  
  77. console.log("Club income " + sum.toFixed(2) + " leva.");
  78.  
  79. } else {
  80.  
  81. console.log("Target acquired");
  82.  
  83. console.log("Club income " + sum.toFixed(2) + " leva.");
  84.  
  85. }
  86.  
  87.  
  88.  
  89.  
  90. }
  91.  
  92. solve(['500', 'Bellini', '6', 'Bamboo', '7', 'Party!']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement