SHARE
TWEET

Untitled

a guest Oct 21st, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.    
  3.    let prices = {
  4.       "js-fundamentals" : 170,
  5.       "js-advanced" : 180,
  6.       "js-applications" : 190,
  7.       "js-web" : 490,
  8.    }
  9.    let names = {
  10.       "js-fundamentals" : "JS-Fundamentals",
  11.       "js-advanced" : "JS-Advanced",
  12.       "js-applications" : "JS-Applications",
  13.       "js-web" : "JS-Web",
  14.       "HTML and CSS" : "HTML and CSS",
  15.    }
  16.  
  17.  
  18.    document.getElementsByTagName("button")[0]
  19.       .addEventListener("click", (e)=>{
  20.       let selectedCourses = [...document.querySelectorAll("[type=checkbox]")]
  21.       .filter(x=>x.checked===true)
  22.       .map(x=>x.value);
  23.  
  24.       if (selectedCourses.includes("js-advanced")
  25.       && selectedCourses.includes("js-fundamentals")) {
  26.          prices["js-advanced"] = 0.9*prices["js-advanced"];
  27.       }
  28.      
  29.       let total = selectedCourses
  30.                   .reduce((price,curr)=>price+prices[curr],0);
  31.  
  32.       if (selectedCourses.includes("js-advanced")
  33.       && selectedCourses.includes("js-fundamentals")
  34.       && selectedCourses.includes("js-applications")) {
  35.          total = 0.94*total;
  36.       }
  37.  
  38.       if (selectedCourses.includes("js-advanced")
  39.        && selectedCourses.includes("js-fundamentals")
  40.        && selectedCourses.includes("js-applications")
  41.        && selectedCourses.includes("js-web")) {
  42.          selectedCourses.push("HTML and CSS");
  43.       }
  44.  
  45.       let onlineCourse = document.querySelectorAll("input[type=radio]")[1];
  46.       if (onlineCourse.checked === true) {
  47.          total = 0.94*total;
  48.       }
  49.      
  50.       let cost = document.getElementsByClassName("courseFoot")[1].getElementsByTagName("p")[0];
  51.       cost.innerText = `Cost: ${Math.floor(total).toFixed(2)} BGN`;
  52.  
  53.       document.getElementById("myCourses").childNodes;
  54.  
  55.       const ul = document.getElementsByClassName("courseBody")[1].getElementsByTagName("ul")[0];
  56.       selectedCourses
  57.       .forEach(e=>{
  58.       const li = document.createElement("li");
  59.       li.innerText = names[e];
  60.       ul.appendChild(li);
  61.       });
  62.    });
  63. }
  64.  
  65. solve();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top