Advertisement
svetlyoek

Untitled

Jun 26th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. function solve() {
  2.  
  3. const taskField = document.getElementById('task');
  4. const descriptionField = document.getElementById('description');
  5. const dateField = document.getElementById('date');
  6. const addBtn = document.getElementById('add');
  7.  
  8. const openDiv = document.querySelector('.wrapper section:nth-child(2) div:nth-child(2)');
  9. const progressDiv = document.querySelector('.wrapper section:nth-child(3) div:nth-child(2)');
  10. const completeDiv = document.querySelector('.wrapper section:nth-child(4) div:nth-child(2)');
  11.  
  12. addBtn.addEventListener('click', function (e) {
  13. e.preventDefault();
  14.  
  15. if (taskField.value !== '' && descriptionField.value !== '' && dateField.value !== '') {
  16.  
  17. const article = document.createElement('article');
  18. const heading3 = document.createElement('h3');
  19. const descriptionParagraph = document.createElement('p');
  20. const dateParagraph = document.createElement('p');
  21. const divFlex = document.createElement('div');
  22. const startBtn = document.createElement('button');
  23. const deleteBtn = document.createElement('button');
  24. const finishBtn = document.createElement('button');
  25.  
  26. heading3.textContent = taskField.value.trim();
  27. descriptionParagraph.textContent = `Description: ` + descriptionField.value.trim();
  28. dateParagraph.textContent = `Due Date: ` + dateField.value.trim();
  29. startBtn.textContent = 'Start';
  30. deleteBtn.textContent = 'Delete';
  31. finishBtn.textContent = 'Finish';
  32.  
  33. article.appendChild(heading3);
  34. article.appendChild(descriptionParagraph);
  35. article.appendChild(dateParagraph);
  36.  
  37. divFlex.classList.add('flex');
  38. startBtn.classList.add('green');
  39. deleteBtn.classList.add('red');
  40. finishBtn.classList.add('orange');
  41.  
  42. divFlex.appendChild(startBtn);
  43. divFlex.appendChild(deleteBtn);
  44.  
  45. article.appendChild(divFlex);
  46.  
  47. openDiv.appendChild(article);
  48.  
  49. document.getElementById('task').value = '';
  50. document.getElementById('description').value = '';
  51. document.getElementById('date').value = '';
  52.  
  53. startBtn.addEventListener('click', function (e) {
  54.  
  55. progressDiv.appendChild(article);
  56. startBtn.remove();
  57. divFlex.appendChild(finishBtn);
  58. });
  59.  
  60. finishBtn.addEventListener('click', function (e) {
  61.  
  62. completeDiv.appendChild(article);
  63.  
  64. divFlex.remove();
  65. });
  66.  
  67. deleteBtn.addEventListener('click', function (e) {
  68.  
  69. article.remove();
  70. });
  71. }
  72. });
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement