Advertisement
GeorgiLukanov87

01. Dish Manager - JS Advanced Exam - 22 October 2022

Mar 20th, 2023 (edited)
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JS Advanced Retake Exam - 10 Aug 2022
  2. // 01. Dish Manager
  3. // https://judge.softuni.org/Contests/Practice/Index/3565#0
  4.  
  5. function solve() {
  6.   let formBtn = document.getElementById('form-btn');
  7.   formBtn.addEventListener('click', submitHandler);
  8.  
  9.   let firstName = document.getElementById('first-name');
  10.   let lastName = document.getElementById('last-name');
  11.   let age = document.getElementById('age');
  12.  
  13.   let description = document.getElementById('task');
  14.   let ulInProgress = document.getElementById('in-progress');
  15.   let ulFinished = document.getElementById('finished');
  16.   let inProgress = document.getElementById('progress-count');
  17.   let progressCounter = 0;
  18.   let clearBtn = document.getElementById('clear-btn');
  19.  
  20.   function submitHandler() {
  21.     if (firstName.value == '' ||
  22.       lastName.value == '' ||
  23.       age.value == '' ||
  24.       description.value == '') {
  25.       console.log('fail')
  26.       return;
  27.     }
  28.     let gender = document.getElementById('genderSelect');
  29.     let genderOption = gender.options[gender.selectedIndex].text;
  30.  
  31.     let savedData = {
  32.       firstName: firstName.value,
  33.       lastName: lastName.value,
  34.       age: age.value,
  35.       gender: gender.options[gender.selectedIndex].text,
  36.       description: description.value,
  37.     }
  38.  
  39.     let newLi = document.createElement('li');
  40.     newLi.setAttribute('class', 'each-line');
  41.     newLi.innerHTML = `
  42.     <article>
  43.     <h4>${firstName.value} ${lastName.value}</h4>
  44.     <p>${savedData['gender']}, ${age.value}</p>
  45.     <p>Dish description: ${description.value}</p>
  46.     </article>
  47.     <button class="edit-btn">Edit</button>
  48.     <button class="complete-btn">Mark as complete</button>
  49.     `
  50.     ulInProgress.appendChild(newLi);
  51.     firstName.value = '';
  52.     lastName.value = '';
  53.     age.value = '';
  54.     description.value = '';
  55.     progressCounter++;
  56.     inProgress.textContent = progressCounter;
  57.     let editBtn = document.querySelector('#in-progress > li > button.edit-btn');
  58.     let completeBtn = document.querySelector('.complete-btn');
  59.  
  60.     editBtn.addEventListener('click', editHandler);
  61.     completeBtn.addEventListener('click', completeHandler);
  62.  
  63.     function editHandler(e) {
  64.       console.log(e.target)
  65.       firstName.value = savedData['firstName'];
  66.       lastName.value = savedData['lastName'];
  67.       age.value = savedData['age'];
  68.       gender.value = savedData['gender'];
  69.       description.value = savedData['description'];
  70.       progressCounter--;
  71.       inProgress.textContent = progressCounter;
  72.       newLi.remove();
  73.        
  74.     }
  75.     function completeHandler(e) {
  76.       ulFinished.appendChild(newLi)
  77.       editBtn.remove();
  78.       completeBtn.remove();
  79.       progressCounter--;
  80.       inProgress.textContent = progressCounter;
  81.        
  82.     }
  83.     clearBtn.addEventListener('click', clearHander);
  84.     function clearHander(e) {
  85.       ulFinished.remove();
  86.        
  87.     }
  88.   }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement