Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rotem-bendavid
Copy link

No description provided.

</div>
<div class="bottom">
<span class="howMany"></span>
<button type="button" class="sort" style="display:none">sort</button>

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");

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");

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) {

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();">&#x1F5D1;</span></li>';

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 &#x1F5D1; 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;

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");

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");

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();

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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using classes is preferred

Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants