Last active
January 4, 2022 20:19
-
-
Save a1ip/d26a9ca8887a3396ffa9c269cd5614ee to your computer and use it in GitHub Desktop.
Решение испытания «Список задач — Условия и создание элементов» из курса «Знакомство с JavaScript» https://htmlacademy.ru/courses/347/run/16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let list = document.querySelector('.todo-list'); | |
let input = document.querySelector('.todo-input'); | |
let form = document.querySelector('.todo-form'); | |
let priority = document.querySelector('.todo-priority'); | |
priority.onclick = function () { | |
priority.classList.toggle('is-important'); | |
if (priority.classList.contains('is-important')) { | |
priority.textContent = 'Важная задача'; | |
} else { | |
priority.textContent = 'Обычная задача'; | |
} | |
}; | |
form.onsubmit = function (evt) { | |
evt.preventDefault(); | |
}; | |
form.onsubmit = function (evt) { | |
evt.preventDefault(); | |
let task = document.createElement('li'); | |
task.textContent = input.value; | |
if (priority.classList.contains('is-important')) { | |
task.classList.add('is-important'); | |
} else { | |
task.classList.remove('is-important'); | |
} | |
list.append(task); | |
input.value = ''; | |
}; | |
/* | |
1. Каждая задача в списке — это элемент li. При отправке формы (переменная form) новая задача добавляется в конец списка (переменная list). | |
2. Текст задачи берётся из поля ввода (переменная input). | |
3. Если у переключателя приоритета (переменная priority) есть класс is-important, то новой задаче также добавляется класс is-important. | |
4. Бонус: после того, как задача добавится в список, поле ввода можно очистить. Но можно не очищать. Подходят оба варианта. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment