Design comparison
Solution retrospective
Hi,
I need help with my JavaScript.
As you can see in my script I have three functions (dailyCards, weeklyCards, and monthlyCards) I'd like to ask if I can make it only in one function because they have only small differences.
Thank you so much for helping out.
Community feedback
- @Aadv1kPosted over 2 years ago
Good job on breaking down your JS into functions, that is a good practice, so, here is a simple fix; remove all the other functions and just have a single one
getCard(date)
where the date is either daily, monthly or weekly, then simply in your template replace${item.timeframes.daily.current}
with${item.timeframes.[date]['current']}
(do this will all the references) and voilaMarked as helpful2@Tuason066Posted over 2 years agoHi @Aadv1k,
Thank you so much for your help. It resolves my problem and this will help me to improve my skills.
I just want to ask is this how we can pass a parameter/argument inside of the template string. [parameter/argument] using square brackets?
1@Aadv1kPosted over 2 years ago@Tuason066 in a object there are two ways to get a property, one is by the dot method
foo.bar
second is thefoo['bar']
to access a key using a variables you have to use the second onfoo[variable]
, it doesn't matter if it's in a template string or as-is, feel free to clarify your doubts if you have any more, Im happy to help0@Tuason066Posted over 2 years ago@Aadv1k
For now this the only question I have. Thank you so much for enlighten me.
Happy coding.
0
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