I used sublime text and basic javascipt to make a functionable buttons
Design comparison
Solution retrospective
As I am beginner in web development I find it difficult to working with javascript , like which type of functions to create or use event listener, But i managed to create a calculator in which i can enter all number input in the textfield by clicking buttons. It can be further improved by applying little more javascript. You can improve it if you like , if you do please let me know the methods you've had applied.
Community feedback
- @khaya05Posted about 2 years ago
Hi ππ½ππ½, nice job on trying to create this project.
I can see that you added
eventListeners
on all buttons, which works but I think it's better to add the event listener on the parent, which in this case isdiv class='keyscontainer
, like this<div class="keys"> <button data-key="7">7</button> <button data-key="8">8</button> <button data-key="9">9</button> <button data-key="DEL">DEL</button> <button data-key="4">4</button> <button data-key="5">5</button> <button data-key="6">6</button> <button data-key="+">+</button> <button data-key="1">1</button> <button data-key="2">2</button> <button data-key="3">3</button> <button data-key="-">-</button> <button data-key=".">.</button> <button data-key="0">0</button> <button data-key="/">/</button> <button data-key="x">x</button> <button id="resetbtn" data-key="reset">Reset</button> <button id="enterbtn" data-key="equals">=</button> </div>
This is called dom traversing. Check this video by WebDevSimplified: video_1
Then this is what you might do on your
.js
const keysContainer = document.querySelector('.keys'); keysContainer.addEventListener('click', (e) => { const key = e.target.dataset.key });
Also, check out this scrimba video video_2
hope this helps you πππ
Marked as helpful0
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