+ 2

I can't understand why it shows problem to execute?

When I change <div id="output"> <p id="result"></p> </div> this code to <p id="output"> <p id="result"></p> </p> it shows the result "5" if the qn includes + sign. but why it is not working with the 1at situation. You can watch the problem in my 2nd code bit if I use the 2nd code it comes down to button section https://code.sololearn.com/WS7r72SOpUYz/?ref=app https://code.sololearn.com/W0d3sWoj77bh/?ref=app

2nd Mar 2023, 8:13 AM
Pooja Sahoo
Pooja Sahoo - avatar
2 odpowiedzi
+ 3
For second code, your #result is positioned in wrong spot, it is inside buttons not screen. Add border to it to see where it is. Thats why when you calculate, date is there. In first code, I can't reproduce same error, it does not calculate when I click = I don't know did you finished this code yet Edit: There is much better way to create calculator, you should have 1 function to take inputed data not separate function to each button. With js, when you use event listeners, like click, you also get event object. With this object you can access what element is clicked and get its value, edit them, and much more... Here is more about event object: https://developer.mozilla.org/en-US/docs/Web/API/Event to select current element we do: function anything(event) { let elem = event.target; // then we can return or edit value, innerText, change style, remove item from dom... return elem.value; }
2nd Mar 2023, 9:03 AM
PanicS
PanicS - avatar
+ 3
Thanks bro(PanicS) couse of you I got the idea of doing it correctly.😊
2nd Mar 2023, 9:12 AM
Pooja Sahoo
Pooja Sahoo - avatar