Design comparison
Solution retrospective
Hi there, thanks for taking the to check out my solution. However, I can't seem to get the discount applied to the prices via the toggle button working. I'd greatly appreciate if someone can point me in the right direction. Have a great day!
Community feedback
- @pranshudobhalPosted almost 4 years ago
Hey Afiq,
To get the discount applied to the prices, you can write your code as below:
function tog(){ console.log(this.checked); } document.querySelector('.toggle').addEventListener('click', tog);
The above code adds an event listener on click on the toggle. So when the toggle is on, this.checked would return true and when it's off, it would return false. So, if this.checked value is true, you can invoke the discount function and when it's false you can display the original price.
Hope this helps! :D
0@akaahlPosted almost 4 years ago@pranshudobhal
Hi Pranshu,
Thanks for the help, will try to implement it later on. Appreciate it. Cheers!
0@akaahlPosted almost 4 years ago@pranshudobhal
Managed to get it done, though I think my code is a bit redundant and repetitive. Would you be kind enough to comment on it? Thanks!
0@pranshudobhalPosted almost 4 years ago@akaahl
If you think your code is redundant, then you can make a function and put the code that is getting repeated in it, and call the function whenever you want it to run again.
0@akaahlPosted almost 4 years ago@pranshudobhal
Yeap, I think that would make it more cleaner. Thanks!
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