re: Day 17: I hate programming VIEW POST

re: I'd really appreciate that. Here is the html and the javascript. And this the javascript code before i started making changes.

I initially had a self invoking function to get habits from the database, loop through and display them on the web. I was trying to refactor that code to allow me to call it in the add habits function and pass new habit as a parameter. This was my reference but I get keep getting an error that displayHabits is not a function.

I see that. I'm not sure that it is necessary to wrap the function as self executing. displayHabits 1. doesn't take any arguments when you define it but you are giving it an argument when you attempt to use it later in the code. 2. displayHabits fires itself first then returns itself to displayHabits.
I would simplify and make two functions
let displayInitialHabits = async function () {
// axios call to get saved habits and then display them
// then when document is loaded
// and another function to add a new habit on form submit
let addHabit = async function (event) {
// get form data and save as a new habit
// clear form inputs after save
// add new habit to the list

Okay, I see why i'm getting the error. I'll refactor the code to follow a similar format.

Code of Conduct Report abuse