Day 20: Code Refactoring

mtee

Margaret W.N

Posted on August 5, 2020

Day 20: Code Refactoring

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)
  }
}
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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

πŸ’– πŸ’ͺ πŸ™… 🚩
mtee
Margaret W.N

Posted on August 5, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Day 23 of 100DaysOfCode
javascript Day 23 of 100DaysOfCode

October 3, 2024

Day21 of 100DaysOfCode
javascript Day21 of 100DaysOfCode

August 22, 2024

Day22 of 100DaysOfCode
javascript Day22 of 100DaysOfCode

September 7, 2024

Day 2 of #100daysofMiva Coding Challenge
100daysofmiva Day 2 of #100daysofMiva Coding Challenge

August 22, 2024