Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Interactive pricing component

@KorniDoS

Desktop design screenshot for the Interactive pricing component coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Initially i had some issues coming up with a non-buggy solution for discount toggle button functionality, eventually i came up with the idea of nesting another event listener (for the discount disable) inside the main toggle event listener. My question is, what could have been a better solution for this? I also have a question regarding the desktop css layout. I've had some issues getting the desired layout while using grid for the last two items (the perks list and trial button). I could not simply align and justify only these items and had to "cheat" and use negative margin-top and some margin-bottom. What could have been the reason for this? Thank you for your time!

checkbox.checked = false; //Set toggle button off by default
//Nested event listeners for on-off toggling functionality
function monthly_yearly_billing(){ //Toggle button on - discount activated!
        checkbox.checked = true; //Activated button
        price_range.removeEventListener('input', mainPrices);//Remove the main prices event
        price_range.addEventListener('input', discountPrices);//Add the discount prices event
        discountPricesBasedOnCounterValue(counter);//Show discount price after toggling - eg(16$ off button - 12$ on button; 36$ off button - 27$ on button)
        this.removeEventListener('click', monthly_yearly_billing); //remove this function from within it's own context (so that it won't always fire itself first and not be able to disable the button after 2nd click)



         checkbox.addEventListener('click', function(){ //Second click event - turn off
                     checkbox.checked = false;
                     price_range.removeEventListener('input', discountPrices); //Remove discount prices event
                     price_range.addEventListener('input', mainPrices); //Add main prices event back
                     mainPricesBasedOnCounterValue(counter);//Show main price again after toggling 
                    this.addEventListener('click', monthly_yearly_billing); //Add the toggle-on function back!
        })
  
}
checkbox.addEventListener('click', monthly_yearly_billing);

Community feedback

Please log in to post a comment

Log in with GitHub
Discord logo

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