Calculator designed using grid and flexbox, Javascript
Design comparison
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)); } }
Community feedback
- @tientaidevPosted over 1 year ago
- 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 ^^
0@juarezv90Posted over 1 year ago@tientaidev Made a few clean updates to the JS and screen function would should fix the issues you saw. Should not give number issues and made sure the user is not able to add multiple decimals in randon places.
0 - When I press
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