Responsive Multi-step-form with SCSS and vanilla JS
Design comparison
Solution retrospective
Hello, hope you doing well, i made this by my own so i would like to hear how can i improve html accesibility and JS best practices
Community feedback
- @rudimediazPosted almost 2 years ago
wow, i appreciate your guts for making it in vanilla js. The info field validations seem great (something that i don't really care in my solution).
I think your solution got a serious problem on total summary step. I found you calculate it twice tho.
in here
planOptions.forEach((plan) => { let costOfPlans = plan.querySelectorAll('.cost'); costOfPlans.forEach(cost => { if (cost.classList.contains('yearly-cost') && plan.classList.contains('active')) { totalPlanCost *= 10; // this set the value of the total cost ShowPlanCost(plan); } }) }); /// planOptions.forEach((plan) => { let costOfPlans = plan.querySelectorAll('.cost'); costOfPlans.forEach(cost => { if (cost.classList.contains('monthly-cost') && plan.classList.contains('active')) { totalPlanCost /= 10; ShowPlanCost(plan); } }) });
and here
function getTotal(changeValue) { let localTotal = totalPlanCost; if(changeValue) { if(!switchOptions.checked) { totalCount.innerText = '+$' + localTotal / 10 + '/mo'; } // yearly access else { totalCount.innerText = '+$' + localTotal * 10 + '/yr'; } // monthly access } else { if(!switchOptions.checked) { totalCount.innerText = '+$' + localTotal + '/mo'; } // yearly access else { totalCount.innerText = '+$' + localTotal * 10 + '/yr'; } // monthly access } }
Be careful when you attemp to imperatively mutating state. Try to using pure function (or maybe using object that has getter and setter if you OOP person) for calculation stuff. If you are not careful enough, you may lead it into a bug.
and one more thing, 'console.log's. try remove them before you push your code into production.
Marked as helpful0@carlpyPosted almost 2 years ago@rudimediaz Thanks for your reply, really apreciate it , about the total step, was really confusing but i'll try to figure out how to make the best of that error, and fixed, if you have an idea to make that let me know, greets
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