-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ex. 1 - Rotem Ben David #14
base: main
Are you sure you want to change the base?
Conversation
</div> | ||
<div class="bottom"> | ||
<span class="howMany"></span> | ||
<button type="button" class="sort" style="display:none">sort</button> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a class instead of an inline style attribute is always better. Only in specific cases, using an inline style is preferred.
@@ -0,0 +1,89 @@ | |||
let input = document.querySelector(".newTask input"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could also be a constant.
Moreover, you could have used a more straightforward name. input is too generic and doesn't say much about the element it points at.
@@ -0,0 +1,89 @@ | |||
let input = document.querySelector(".newTask input"); | |||
const add = document.querySelector(".newTask button"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you could have used a more specific name
//show the tasks | ||
function showTasks(newTask) { //adds new task to tasks array and adds it to html | ||
let newLiTag = ''; | ||
if (newTask != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 38-40 should have been part of addNewTask
This is the code that adds the task to the tasks array.
showTasks
should be in charge of showing the tasks. No more logic should be in it.
tasks.push(newTask); | ||
} | ||
tasks.forEach((element, index) => { | ||
newLiTag += '<li onClick="taskAlert('+index+')">'+element+'<span onClick="deleteTask('+index+');event.stopPropagation();">🗑</span></li>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You called the variable newLiTag
and eventually, it holds multiple li tags, each for every task in the tasks array.
Besides it, it is not clear what 🗑
means. Make sure you add explanations when you code is not 100% straightforward.
else { //delete clear all button when there aren't tasks | ||
showClearAll.style = 'display: none'; | ||
showSort.style = 'display: none'; | ||
howManyTasks.innerHTML = defultMassage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defultMassage
is not clear.
const tasksView = document.querySelector(".tasks"); | ||
const tasks = []; | ||
const howManyTasks = document.querySelector(".bottom .howMany"); | ||
const showClearAll = document.querySelector(".bottom .clear"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearAllButtom
would be a better name
const tasks = []; | ||
const howManyTasks = document.querySelector(".bottom .howMany"); | ||
const showClearAll = document.querySelector(".bottom .clear"); | ||
const showSort = document.querySelector(".bottom .sort"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sortButton
would be a better name
|
||
//sort | ||
showSort.addEventListener('click', () => { //recognize click on 'sort' button | ||
tasks.sort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort without a function is usually not recommended as it is unclear how the array is sorted.
newSpan = '<span>You have '+tasks.length+' pending tasks</span>' | ||
howManyTasks.innerHTML = newSpan; | ||
if (tasks.length === 1) { //display clear all button only when there are tasks | ||
showClearAll.style = 'display: block'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using classes is preferred
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@or-nuri-monday can you please explain what do you mean? (I fixed all other commants)
No description provided.