Guest User

Untitled

a guest
Oct 18th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. function solve() {
  2.  
  3. let threeHave = false;
  4.  
  5. let theBonusCourse = false;
  6.  
  7. let onlineDiscount = false;
  8.  
  9. let totalPrice = 0;
  10.  
  11. let array = [];
  12.  
  13. const theUl = document.querySelector("#myCourses > div.courseBody > ul");
  14.  
  15. let ObjectPrices = {
  16. 'js-fundamentals': 170,
  17. 'js-advanced': 180,
  18. 'js-applications': 190,
  19. 'js-web': 490
  20. }
  21.  
  22. let ObjectNames = {
  23. 'js-fundamentals': 'JS Fundamentals',
  24. 'js-advanced': 'JS Advanced',
  25. 'js-applications': 'JS Applications',
  26. 'js-web': 'JS Web'
  27. }
  28.  
  29. let result = document.querySelector("#myCourses > div.courseFoot > p");
  30.  
  31. const btnSighnMeUp = document.querySelector("#availableCourses > div.courseFoot > button");
  32.  
  33. const bottons = Array.from(document.getElementsByTagName('INPUT'));
  34.  
  35. bottons.forEach(bottons => bottons.addEventListener('click', start));
  36.  
  37. function start(event) {
  38.  
  39. const btn = event.target;
  40.  
  41. const status = document.querySelector("#educationForm > input[type=radio]:checked").value;
  42.  
  43. if (status === 'online') {
  44.  
  45. onlineDiscount = true
  46. }
  47.  
  48. array.push(btn.value);
  49.  
  50. }
  51.  
  52. btnSighnMeUp.addEventListener('click', end);
  53.  
  54. function end() {
  55.  
  56. if (array.includes('js-advanced') && array.includes('js-fundamentals')) {
  57.  
  58. ObjectPrices['js-advanced'] = 162;
  59. }
  60.  
  61. if (array.includes('js-advanced') && array.includes('js-fundamentals') && array.includes('js-applications')) {
  62.  
  63. threeHave = true;
  64.  
  65. totalPrice -= 32.4
  66.  
  67. }
  68.  
  69. if (array.includes('js-advanced') && array.includes('js-fundamentals') && array.includes('js-applications') && array.includes('js-web')) {
  70.  
  71. theBonusCourse = true;
  72.  
  73. }
  74.  
  75. for (let i = 0; i < array.length; i++) {
  76.  
  77. if (array[i] !== "online" && array[i] !== "onsite") {
  78.  
  79. totalPrice += ObjectPrices[array[i]];
  80. }
  81.  
  82. }
  83.  
  84. if (onlineDiscount === true) {
  85. totalPrice *= 0.94;
  86. }
  87.  
  88. totalPrice = Math.floor(totalPrice) + '.00';
  89.  
  90. result.innerHTML = `Cost: ${totalPrice} BGN`;
  91.  
  92. for (let k = 0; k < array.length; k++) {
  93.  
  94. if (array[k] !== "online" && array[k] !== "onsite") {
  95. let node = document.createElement("LI");
  96. let a = ObjectNames[array[k]];
  97. var textnode = document.createTextNode(a);
  98. node.appendChild(textnode);
  99. theUl.appendChild(node);
  100. }
  101.  
  102. }
  103.  
  104. }
  105.  
  106. }
  107. solve();
Advertisement
Add Comment
Please, Sign In to add comment