@fatemzh
Posted
Congratulations on finishing this challenge, also nice personal touch you added to the activities' cards. To optimize your code further with a loop you could consider gathering the elements into an array first:
const elements = [ { current: workCurrentTime, previous: workPreviousTime }, { current: playCurrentTime, previous: playPreviousTime }, { current: studyCurrentTime, previous: studyPreviousTime }, { current: exerciseCurrentTime, previous: exercisePreviousTime }, { current: socjalCurrentTime, previous: socjalPreviousTime }, { current: selfCareCurrentTime, previous: selfCarePreviousTime } ];
And then, use a loop to iterate over this array and update each element with the corresponding data:
elements.forEach((el, index) => { el.current.textContent = data[index].timeframes.daily.current; el.previous.textContent = data[index].timeframes.daily.previous; });
It's just an idea, hope this helps a bit.
Marked as helpful
@konradbaczyk
Posted
@fatemzh Thank you, I will try implement this next time :)