+ 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

6th May 2020, 5:32 AM
Shubham Thakur
Shubham Thakur - avatar
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.
6th May 2020, 5:52 AM
Kevin ★
+ 3
Hey Shubham Thakur, Check out the corrected code :)) https://code.sololearn.com/WTr2c663VW3S/?ref=app Updated :))
6th May 2020, 6:08 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Thankyou mate 😍
6th May 2020, 1:19 PM
Shubham Thakur
Shubham Thakur - avatar