Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- let threeHave = false;
- let theBonusCourse = false;
- let onlineDiscount = false;
- let totalPrice = 0;
- let array = [];
- const theUl = document.querySelector("#myCourses > div.courseBody > ul");
- let ObjectPrices = {
- 'js-fundamentals': 170,
- 'js-advanced': 180,
- 'js-applications': 190,
- 'js-web': 490
- }
- let ObjectNames = {
- 'js-fundamentals': 'JS Fundamentals',
- 'js-advanced': 'JS Advanced',
- 'js-applications': 'JS Applications',
- 'js-web': 'JS Web'
- }
- let result = document.querySelector("#myCourses > div.courseFoot > p");
- const btnSighnMeUp = document.querySelector("#availableCourses > div.courseFoot > button");
- const bottons = Array.from(document.getElementsByTagName('INPUT'));
- bottons.forEach(bottons => bottons.addEventListener('click', start));
- function start(event) {
- const btn = event.target;
- const status = document.querySelector("#educationForm > input[type=radio]:checked").value;
- if (status === 'online') {
- onlineDiscount = true
- }
- array.push(btn.value);
- }
- btnSighnMeUp.addEventListener('click', end);
- function end() {
- if (array.includes('js-advanced') && array.includes('js-fundamentals')) {
- ObjectPrices['js-advanced'] = 162;
- }
- if (array.includes('js-advanced') && array.includes('js-fundamentals') && array.includes('js-applications')) {
- threeHave = true;
- totalPrice -= 32.4
- }
- if (array.includes('js-advanced') && array.includes('js-fundamentals') && array.includes('js-applications') && array.includes('js-web')) {
- theBonusCourse = true;
- }
- for (let i = 0; i < array.length; i++) {
- if (array[i] !== "online" && array[i] !== "onsite") {
- totalPrice += ObjectPrices[array[i]];
- }
- }
- if (onlineDiscount === true) {
- totalPrice *= 0.94;
- }
- totalPrice = Math.floor(totalPrice) + '.00';
- result.innerHTML = `Cost: ${totalPrice} BGN`;
- for (let k = 0; k < array.length; k++) {
- if (array[k] !== "online" && array[k] !== "onsite") {
- let node = document.createElement("LI");
- let a = ObjectNames[array[k]];
- var textnode = document.createTextNode(a);
- node.appendChild(textnode);
- theUl.appendChild(node);
- }
- }
- }
- }
- solve();
Advertisement
Add Comment
Please, Sign In to add comment