Interactive Pricing Component

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!
Please log in to post a comment
Log in with GitHubCommunity feedback
- @pranshudobhal
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
Join 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