-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
CYF-ITP-South Africa | Serna Malala | Module-Data-Groups | Week 3 Todo List #287
base: main
Are you sure you want to change the base?
Conversation
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.
The code works well. I only have some suggestions and comments for possible code improvement.
listItem.style.background = "lightblue"; | ||
listItem.style.padding = "1em"; | ||
listItem.style.display = "inline-block"; | ||
listItem.style.margin = "0.5em"; | ||
listItem.textContent = todoItem.task; | ||
list.style.margin = "0 auto"; | ||
list.style.backgroundColor = "#FCC4AB"; | ||
body.style.textAlign = "center" |
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.
Why not set CSS styles in styles.css
? That way, whenever we need to change the view we don't have to change the code.
list.style.backgroundColor = "#FCC4AB"; | ||
body.style.textAlign = "center" | ||
|
||
list.appendChild(breakLine); |
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.
Adding <br>
to a list would result in creating something like
<ul>
<li>....</li>
<br>
<li>...</li>
<br>
</ul>
which is considered an error in HTML.
Can you think of a better way to create space between list items using only CSS?
|
||
let todo = {}; | ||
|
||
if (inputFieldValue.length > 0) { |
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.
Do you want to accept any input containing only space characters?
|
||
if (todoID) { | ||
todos.splice(parseInt(todoID), 1); | ||
listItem.remove(); |
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.
Is line 76 necessary? The next statement, populateTodoList()
, will update the whole UI by reconstructing all the elements that make up UI.
|
||
|
||
deleteButton.addEventListener("click", function () { | ||
const listItem = this.closest("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.
Do you know what this
is at line 71?
if (todoID && todos[parseInt(todoID)].completed === false) { | ||
todos[parseInt(todoID)].completed = true; | ||
listItem.style.textDecoration = "line-through"; | ||
|
||
} | ||
else { | ||
todos[parseInt(todoID)].completed = false; | ||
listItem.style.textDecoration = "none"; | ||
} |
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.
Why not just call populateTodoList()
at line 59 and 64 to update the whole UI?
Any chance todoID
is undefined or an empty string?
The code at lines 57-65 could possibly be reduced to 2-3 lines of code.
checkMark.id = todoButtonsIndex; | ||
deleteButton.id = todoButtonsIndex; | ||
todoButtonsIndex++; |
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.
- These id values are not unique.
- Why do you want to assign id to these two buttons? Where are these id values being used?
- If you don't need these id values, you probably won't need
todoButtonsIndex
.
|
||
let todoButtonsIndex = 0; | ||
|
||
let todoButtons = `<span class="badge bg-primary rounded-pill"> |
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.
If todoButtons
does not need to be reassigned a different value later, it is better to declare it using const
.
Learners, PR Template
Self checklist
Changelist
Briefly explain your PR.
I created a todolist app that dynamically adds todo items to the screen using javascript. The check mark and delete buttons also work to strikethrough and delete the items.
Questions
Ask any questions you have for your reviewer.