Calculator designed using grid and flexbox, Javascript

Solution retrospective
Challenges
Most challenges faced were with the handling of calculations for the calculator. Making separate functions and using a loop to assign specific function to most of the keys created a fast coding stance.
- Clicking number function
const numberClick = (element) => { if (needReset) { reset(); } if (screen.innerHTML == 0) { screen.innerHTML = ""; } if ((!isNaN(parseInt(element)) || element == ".") && computation == null) { screen.innerHTML = screen.innerHTML + element; inputOne = screen.innerHTML; } else { screen.innerHTML = screen.innerHTML + element; inputTwo = screen.innerHTML; } };
- For Loop to assign keys function
for (const key of keys) { if (!isNaN(parseInt(key.innerHTML)) || key.innerHTML == ".") { key.addEventListener("click", () => numberClick(key.innerHTML)); } }
Please log in to post a comment
Log in with GitHubCommunity feedback
- @tientaidev
- When I press
73+
, the screen appears 0, it is confusing - When I press
78+-1
, the screen appears 0, it does not seem correct. - I can type
7.89.145.5632
, which does not seem to be a correct number. - I can type
1/.
- I can type
1+.
I would appreciate if you review my site as well ^^
- When I press
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