Design comparison
Solution retrospective
Could use some help please.
Created the 3 themed calculator utilizing flex grid to practice. I used custom colors to practice originality and customization. The themes are toggle using javascript.
I'm posting the incomplete javascript functionality in hopes I can get some pointers. Here's my issue:
I cannot for the life of me figure out how to store the calculator's input data to then be used in the calculation. For example, I will create onclick event handlers for the buttons, but the event handler function cannot return outside of the event handler so I can't store it in an array or variable or whatever i'm trying to store it in. If I can't store it outside the button's functionality, how the heck do I calculate? Maybe there's a perspective i'm not seeing.
So I tried manipulating the span and storing the input into the span, but when I click another event handler it overrides it. Maybe this isn't the right approach. I'm honestly stuck. I watch tutorials but they all approach it in different ways and I'm just trying to do it my own way without just copy pasting their code.
I'm so close to giving up on this calculator. Maybe I wasn't ready for it.
Community feedback
- @IryDevPosted over 1 year ago
Hi @ThatDevDiaz, first of all, I really like your custom themes. 🤩
I understand that you're facing difficulties with the calculator challenge on Frontend Mentor. It's completely normal to feel frustrated when encountering obstacles, but don't give up! I'm here to help you understand how to solve this issue.
Firstly, you're on the right track by using onclick event handlers for the buttons. However, you're correct in noting that values cannot be directly returned outside of these event handlers. To store input data and use it for calculations, you need a slightly different approach.
Instead of returning data from the onclick handlers, you can use global variables to store input data. For instance, create a variable named inputData outside of the event handlers and update this variable inside your onclick handlers based on the button you're clicking. This will help you retain the entered values.
Regarding the issue of data being overwritten in the <span>, you might consider storing the inputs in an array instead of a <span> element. With each button click, add the corresponding value to your array. Then, when you need to perform calculations, you can iterate through this array to retrieve the values.
It's normal that the tutorials you've watched approach the problem in different ways. Each person has their own approach and style. However, experimenting and solving the problem yourself is an excellent way to learn and solidify your understanding.
Feel free to ask more specific questions if you need assistance implementing these suggestions. Keep persevering, as you're on the right path to solving this challenge. Programming can be tough, but every difficulty you overcome brings you closer to success.
I hope you'll this helpful and keep going😄
Marked as helpful0@ThatDevDiazPosted over 1 year ago@IryDev
I came back to say thank you. Your words of encouragement helped me overcome this barrier and I finished the challenge successfully.
https://www.frontendmentor.io/challenges/calculator-app-9lteq5N29/hub?share=true
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