Advertisement
ralichka

Untitled

Dec 9th, 2020
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.    let fundamentals = Array.from(document.getElementsByTagName('input'))[0];
  3.    let advanced = Array.from(document.getElementsByTagName('input'))[1];
  4.    let applications = Array.from(document.getElementsByTagName('input'))[2];
  5.    let web = Array.from(document.getElementsByTagName('input'))[3];
  6.  
  7.    let onSite = Array.from(document.getElementsByTagName('input'))[4];
  8.    let online = Array.from(document.getElementsByTagName('input'))[5];
  9.  
  10.    let button = document.querySelector('.courseFoot button');
  11.  
  12.    let ul = Array.from(document.querySelectorAll('.courseBody ul'))[0];
  13.  
  14.    let fundPrice = 170;
  15.    let advancedPrice = 180;
  16.    let applicationsPrice = 190;
  17.    let webPrice = 490;
  18.  
  19.    let totalCost = 0;
  20.  
  21.    button.addEventListener('click', function () {
  22.  
  23.  
  24.       if (advanced.checked && fundamentals.checked) {
  25.  
  26.  
  27.          advancedPrice *= 0, 9;
  28.       }
  29.       if (fundamentals.checked && advanced.checked && applications.checked) {
  30.  
  31.  
  32.          fundPrice *= 0.94;
  33.          advancedPrice *= 0.94;
  34.          applicationsPrice *= 0.94;
  35.       }
  36.       if (fundamentals.checked && advanced.checked
  37.          && applications.checked && web.checked) {
  38.        
  39.       }
  40.  
  41.       if(online.checked){
  42.          fundPrice *= 0.94;
  43.          advancedPrice *= 0.94;
  44.          applicationsPrice *= 0.94;
  45.          webPrice *= 0.94;
  46.       }
  47.  
  48.       let counter = 0;
  49.  
  50.       let allChecked = Array.from(document.querySelectorAll('input:checked'));
  51.       allChecked = allChecked.filter(x=>x.type !== 'radio');
  52.       let ulMyCourses = document.querySelectorAll('.courseBody ul')[1];
  53.       allChecked.forEach(x => {
  54.          counter++;
  55.  
  56.          if (x.name == 'js-fundamentals') {
  57.             totalCost += fundPrice;
  58.          }
  59.          if (x.name == 'js-advanced') {
  60.             totalCost += advancedPrice;
  61.          }
  62.          if (x.name == 'js-applications') {
  63.             totalCost += applicationsPrice;
  64.          }
  65.          if (x.name == 'js-web') {
  66.             totalCost += webPrice;
  67.          }
  68.          let name = x.name;
  69.          
  70.  
  71.             console.log(allChecked.length)
  72.             let liMyCourses = document.createElement('li');
  73.             liMyCourses.textContent = x.nextElementSibling.textContent.split(' - ')[0];
  74.             liMyCourses.textContent = liMyCourses.textContent.split(' ').join('-');
  75.  
  76.             liMyCourses.setAttribute('name',name);
  77.             ulMyCourses.appendChild(liMyCourses);
  78.             if( allChecked.length === 4 && counter === 4){
  79.                let bonusCourse = document.createElement('li');
  80.                bonusCourse.textContent = 'HTML and CSS';
  81.                ulMyCourses.appendChild(bonusCourse);
  82.             }
  83.          
  84.  
  85.       })
  86.       let costElement = document.querySelector('.courseFoot p');
  87.       costElement.textContent = `Cost: ${(Math.floor(totalCost)).toFixed(2)} BGN`;
  88.    })
  89.  
  90.  
  91.  
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement