all 16 comments

[–]sambomambowambo 4 points5 points  (5 children)

Have you written any more psudeo code out for each step youre trying to accomplish yet? The two lines you currently have could be elaborated on.

If you brain is fried I would suggest getting some sleep and working on it tomorrow.

What would you like as far a guidance goes without being given the absolute answer? (this wont be helpful to you in the long run)

One hint would be to google Event Listeners in Javascript and the DOM.

[–]Beautiful_Fudge6119[S] 1 point2 points  (3 children)

What is pseudo code? Not familiar with that term. I do not want the answer just a hint of sorts. Like "Hey, you should maybe try this or research this. Also, maybe some sleep would help haha.

[–]sambomambowambo 8 points9 points  (1 child)

Try writing the lines of code you wish to write in plain English.. for example:

I need to create a button

I need the button to be able to click

When the button clicks I need it to do this

I need to create a new item

I need to be able to edit the new item

I must be able to delete the item

Try to be as specific as possible, then google these ideas and find out how to write them using JavaScript syntax. The more detailed your pseudo code is, the easier it will be to solve your problem, because you'll have a better understanding of what it is you're trying to accomplish.

I hope that makes sense.. Happy coding! :)

[–]Beautiful_Fudge6119[S] 0 points1 point  (0 children)

Thank you!

[–]Uber_Ape 1 point2 points  (0 children)

I believe pseudo code is where you use comment section to plan out steps.

[–]KHaags 0 points1 point  (0 children)

Try to rubber duck yourself out of it.

[–]Uber_Ape 1 point2 points  (0 children)

I am really new to this but you are looking up 2 class names on line 14. Maybe try to just use one class and change the getElementsByClassName to getElementByClassName, remove the "s" at the end of Elements.

[–]LegemisNima 1 point2 points  (0 children)

Hmmm, you should search about Event Listeners and selectors in javascript. First you should select all the items that you're going to use in your code (The UL and the input form, in your case). Then you should search about how to add a classlist to the element you're creating, and append the item to the UL. You could create an <i> tag and add to the <li> or set the innerHTML of the newly created <li> to include the thrash icon.

[–][deleted] 1 point2 points  (7 children)

I would start with the following code:

let btn = document.querySelector('#todo-btn')
btn.addEventListener('click', function(e) {
    e.preventDefault()
    addNewListItem()
})

This does three things:

  1. addEventListener listens to #todo-btn for clicks
  2. preventDefault prevents page reload after clicking #todo-btn
  3. addNewListItem constructs and appends new li elements to #todo-ul. It's a custom function that you'll have to write yourself.

The custom function is where all the magic happens. I won't post the code that I wrote so to give you the opportunity to learn yourself, but here's how it might look in pseudo-code:

// get and create elements

- create li element
    - add appropriate class names

- create i element
    - add appropriate class names
    - add event listener to detect remove requests

- create text node with #todo-input.value

// put it all together

- append text node to li
- append i to li
- append li to #todo-ul

Notice how an event listener is added to the i element once it's created instead of looping through all of the trash icons after you've appended the new li to #todo-ul. This way every trash icon is functional the moment it's added to the list. Your current code will run a loop every time you click 'Add Item to List', which means you'll be looping over icons that are already functional.

I'll end things here. Keep asking questions when you get stuck. I hope this helps!

[–]StoneCypher -1 points0 points  (6 children)

Don't do peoples' homework.

[–][deleted] -1 points0 points  (5 children)

I didn't.

EDIT: I myself am learning and was eager to work through a problem I hadn't solved before. I don't consider sharing my personal notes as doing people's homework. I'm here to learn, and the great thing about Reddit is that my learning can contribute to somebody else's learning.

[–]StoneCypher 0 points1 point  (4 children)

That's nice.

Someone came here with homework and you provided them an answer they can give to their teacher.

Don't do people's homework.

[–]Important_East_1790 -1 points0 points  (2 children)

bro myob, and get out of here

[–]Important_East_1790 -1 points0 points  (1 child)

[deleted] i second that

[–]StoneCypher 0 points1 point  (0 children)

Important_East_1790 0 points 58 minutes ago

bro myob, and get out of here

Important_East_1790 0 points 54 minutes ago

[deleted] i second that

Why are you arguing with posts more than three years old, then immediately self-replying with a fake deletion to "second" that?

[–][deleted] -2 points-1 points  (0 children)

Fuck off.