+ 1
Javascript function not working.
Help me I'm new to coding I'm trying to learn javascript..in this code I want that whenever someone click on the right answer button will change its color to green and if someone click on wrong answer it will turn to red I have tried but don't know how to do it. https://code.sololearn.com/W0I0B3W3eGx8/?ref=app
3 odpowiedzi
+ 4
The function name is:
getElementsByClassName
And this is how you call it:
btn = document.getElementsByClassName('btn')
btn now holds a NodeList(array-like object containing all elements of class "btn") and you need to use [ ] notation to access individual elements.
Your logic is wrong.
In onclick attribute pass a value (maybe a number) to know wich button was clicked.
Use a named parameter in your function declaration to gather the result and do the logic.
Remember: btn[0] is your first button.
btn[1] is your second one, etc.
+ 3
Hey Shubham Thakur, Check out the corrected code :))
https://code.sololearn.com/WTr2c663VW3S/?ref=app
Updated :))
0
Thankyou mate 😍