Always error when i click button | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Always error when i click button

I want to add numbers to the array every time I click the button and display the element array on the p element with id = "demo". but instead an error 'occurred when I felt there was nothing wrong with my code, someone help me solve this error problem' and explain to me why this could happen. https://code.sololearn.com/WFg82Ck9lSW9/?ref=app

28th Nov 2019, 6:46 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
5 Answers
+ 1
I've debugged your code, here it is : https://code.sololearn.com/W6QU3vsTWqBO/?ref=app
28th Nov 2019, 7:10 PM
LISANGOLA BONDJALI CHRISTIAN
LISANGOLA BONDJALI CHRISTIAN - avatar
+ 1
You wrote 1) object.innerHtml instead of object.innerHTML 2) your event Listener was defined in a bad way : instead of having like the following, you added a { as if all your function was an object : idBtn.addEventListener("click",function(){...})
28th Nov 2019, 7:21 PM
LISANGOLA BONDJALI CHRISTIAN
LISANGOLA BONDJALI CHRISTIAN - avatar
+ 1
geez I'm so careless 😥 Thank you very much for answering
28th Nov 2019, 7:30 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
0
LISANGOLA BONDJALI CHRISTIAN Is this because I didn't assign a value to variable a? But before that, thank you for answering my question
28th Nov 2019, 7:12 PM
Hafizd Jubaidir
Hafizd Jubaidir - avatar
0
Juste see your code where you add the event listener, how the callback is defined
28th Nov 2019, 7:22 PM
LISANGOLA BONDJALI CHRISTIAN
LISANGOLA BONDJALI CHRISTIAN - avatar