@IryDev
Posted
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 helpful
@ThatDevDiaz
Posted
@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