0
where is the problem?
<!DOCTYPE html> <html> <head> <title>javascript</title> </head> <body> <p id="demo"></p> <script type="text/javascript"> var name=["ahbab","ahmed","rafid"] document.getElementById("demo").innerHTML=name[2]; </script> </body> </html>
7 Réponses
0
I think that (name) is reserved like (var, const, let, if, else, do ...etc) but I'm not sure
+ 1
oh! i see..
0
I think you need window.onload function on sololearn to properly run js but I may be wrong
0
Ahbab Ahmed Rafid I just added an (s) to name to make it plural and it works
JS is too smart, lol
Because you said name, maybe that's why it chooses the first name and count from 0, 1, 2 and pop up (b) because it is number 2 of the first name, BTW this is my understanding 😂
Just change name to names and it will work
0
is this a rule?😮
0
Ahbab Ahmed Rafid
name is used as an attribute of the an element, so it could occur in DOM code.
0
Use the camel case to indicate a variable. For example, the "userName". This technique will permanently eliminate such errors