Hello! congratulations on completing the challenge!
I recommend that you make the eventListener outside the forEach loop or make use of Event Delegation to improve the performance of the website.
I also recommend that you move the fetch outside, since every time one of the buttons changes you are fetching the data.json again.
The switch and those 3 functions are unnecessary...
function update(data, btnValue){
let text;
if(btnValue === 'daily'){
text = 'Previous'
}else if(btnValue === 'weekly'){
text = 'Last Week'
}else if(btnValue === 'monthly'){
text = 'Last Month''
}
workHours.innerText = data[0].timeframes[btnValue].current + "hrs";
workPrevious.innerText = `${text} - ${data[0].timeframes[btnValue].previous}hrs`;
playHours.innerText = data[1].timeframes[btnValue].current + "hrs";
playPrevious.innerText = `${text} - ${data[1].timeframes[btnValue].previous}hrs`;
studyHours.innerText = data[2].timeframes[btnValue].current + "hrs";
studyPrevious.innerText = `${text} - ${data[2].timeframes[btnValue].previous}hrs`;
exerciseHours.innerText = data[3].timeframes[btnValue].current + "hrs";
exercisePrevious.innerText = `${text} - ${data[3].timeframes[btnValue].previous}hrs`;
socialHours.innerText = data[4].timeframes[btnValue].current + "hrs";
socialPrevious.innerText = `${text} - ${data[4].timeframes[btnValue].previous}hrs`;
selfCareHours.innerText = data[5].timeframes[btnValue].current + "hrs";
selfCarePrevious.innerText = `${text} - ${data[5].timeframes[btnValue].previous}hrs`;
}
Then you would use it like this:
update(data, selectedIme)
In the code above you would be replacing the daily, weekly and monthly functions with a single one.
Remember that you can access a property of an object using square bracket notation too!
obj[property]
obj.property
I didn't understand what you said about svgs... but there are some times where you need to change one of the elements within the svg for the color to change, example
svg path{
color: white;
}
If you need help with something else, remember that you can do reply.
Sorry, I had to delete my last comment because I thought data returned 'daily', 'weekly' or 'monthly' and it didn't...
I hope this helps!