Design comparison
SolutionDesign
Solution retrospective
If i have this function where i pass the parameter "date" how can i replace it into the array without having to create three loops ?
if (choice == 'daily') {
for(let i=0; i < frametimeHours.length; i++) {
frametimeHours[i].innerHTML = trackData[i].timeframes.daily.current + "hrs";
frametimeLastWeek[i].innerText = "Last Week - " + trackData[i].timeframes.daily.previous + "hrs";
}
}
if (choice == 'weekly') {
for(let i=0; i < frametimeHours.length; i++) {
frametimeHours[i].innerText = trackData[i].timeframes.weekly.current + "hrs";
frametimeLastWeek[i].innerText = "Last Week - " + trackData[i].timeframes.weekly.previous + "hrs";
}
}
if (choice == 'monthly') {
for(let i=0; i < frametimeHours.length; i++) {
frametimeHours[i].innerText = trackData[i].timeframes.monthly.current + "hrs";
frametimeLastWeek[i].innerText = "Last Week - " + trackData[i].timeframes.monthly.previous + "hrs";
}
}
}
Community feedback
- @MohammedChakerPosted almost 3 years ago
you can use bracket notation
function switchDate(choice) { for(let i=0; i < frametimeHours.length; i++) { frametimeHours[i].innerHTML = trackData[i].timeframes[choice].current + "hrs"; frametimeLastWeek[i].innerText = "Last Week - " + trackData[i].timeframes[choice].previous + "hrs"; } }
maybe it may help you : click me
good luck..
Marked as helpful1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord