loading...

Day 20: Code Refactoring

mtee profile image Margaret W.N ・1 min read

I refactored the code in consuming API's to two functions as a way to separate concerns. One function gets the habits from the database while the other displays the habits on a webpage.

let getHabits = async function () {
  try {
    const response = await axios({
      url: 'http://localhost:4000/habittracker/habits',
      method: 'get'
    })
    displaySavedHabits(response);
  }
  catch (err) {
    console.log(err)
  }
}

I'll simply call the displaySavedHabits() function inside the gethabits() and pass in response as a parameter.

let displaySavedHabits = function (response) {
//code to loop through response data and display on a webpage
}

Meanwhile whats cooking is a function to delete habits from the webpage. I should have the code working in no time.

10 more days down🥳🥳
Day 20

Discussion

markdown guide