Advertisement
pacho_the_python

Untitled

Mar 23rd, 2023
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const taskInput = document.getElementById('task')
  3.     const descriptionInput = document.getElementById('description')
  4.     const dateInput = document.getElementById('date')
  5.     const addBtn = document.getElementById('add')
  6.     const wrapperDiv = document.getElementsByClassName('wrapper')[0]
  7.     const openSection = Array.from(wrapperDiv.children)[1]
  8.     const progressSection = Array.from(wrapperDiv.children)[2]
  9.     const completeSection = Array.from(wrapperDiv.children)[3]
  10.  
  11.  
  12.     addBtn.addEventListener('click', addTask)
  13.  
  14.     function addTask(e) {
  15.         e.preventDefault()
  16.  
  17.         let task = taskInput.value
  18.         let description = descriptionInput.value
  19.         let date = dateInput.value
  20.  
  21.         if (task === '' || description === '' || date === '') {return}
  22.  
  23.         let articleElement = document.createElement('article')
  24.         let h3 = document.createElement('h3')
  25.         h3.textContent = task
  26.  
  27.         let descriptionParagraph = document.createElement('p')
  28.         descriptionParagraph.textContent = `Description: ${description}`
  29.  
  30.         let dateParagraph = document.createElement('p')
  31.         dateParagraph.textContent = `Due Date: ${date}`
  32.  
  33.         let divButtons = document.createElement('div')
  34.         divButtons.classList.add('flex')
  35.  
  36.         let startBtn = createButtons('green', 'Start', startFunc)
  37.         let deleteBtn = createButtons('red', 'Delete', deleteFunc)
  38.         divButtons.appendChild(startBtn)
  39.         divButtons.appendChild(deleteBtn)
  40.  
  41.         articleElement.appendChild(h3)
  42.         articleElement.appendChild(descriptionParagraph)
  43.         articleElement.appendChild(dateParagraph)
  44.         articleElement.appendChild(divButtons)
  45.  
  46.         openSection.lastElementChild.appendChild(articleElement)
  47.  
  48.         taskInput.value = ''
  49.         descriptionInput.value = ''
  50.         dateInput.value = ''
  51.     }
  52.  
  53.  
  54.     function startFunc(startEvent) {
  55.         let currentArticle = startEvent.currentTarget.parentElement.parentElement
  56.         currentArticle.lastElementChild.remove()
  57.         let newDivBtn = document.createElement('div')
  58.         newDivBtn.classList.add('flex')
  59.  
  60.         let newDeleteBtn = createButtons('red', 'Delete', deleteFunc)
  61.         let finishBtn = createButtons('orange', 'Finish', finishFunc)
  62.         newDivBtn.appendChild(newDeleteBtn)
  63.         newDivBtn.appendChild(finishBtn)
  64.         currentArticle.appendChild(newDivBtn)
  65.  
  66.         progressSection.lastElementChild.appendChild(currentArticle)
  67.     }
  68.     function deleteFunc(deleteEvent) {
  69.         let deleteArticle = deleteEvent.currentTarget.parentElement.parentElement
  70.         deleteArticle.remove()
  71.     }
  72.  
  73.     function finishFunc(finishEvent) {
  74.         let finishArticle = finishEvent.currentTarget.parentElement.parentElement
  75.         finishArticle.lastElementChild.remove()
  76.         completeSection.lastElementChild.appendChild(finishArticle)
  77.     }
  78.  
  79.     function createButtons(buttonClass, buttonText, someFunction) {
  80.         let btn = document.createElement('button')
  81.         btn.classList.add(buttonClass)
  82.         btn.textContent = buttonText
  83.         btn.addEventListener('click', someFunction)
  84.         return btn
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement