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>

2nd Feb 2020, 12:48 PM
Ahbab Ahmed Rafid
Ahbab Ahmed Rafid - avatar
7 odpowiedzi
0
I think that (name) is reserved like (var, const, let, if, else, do ...etc) but I'm not sure
2nd Feb 2020, 1:38 PM
JS LOVER
JS LOVER - avatar
+ 1
oh! i see..
2nd Feb 2020, 1:47 PM
Ahbab Ahmed Rafid
Ahbab Ahmed Rafid - avatar
0
I think you need window.onload function on sololearn to properly run js but I may be wrong
2nd Feb 2020, 1:17 PM
HNNX 🐿
HNNX 🐿 - avatar
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
2nd Feb 2020, 1:25 PM
JS LOVER
JS LOVER - avatar
0
is this a rule?😮
2nd Feb 2020, 1:34 PM
Ahbab Ahmed Rafid
Ahbab Ahmed Rafid - avatar
0
Ahbab Ahmed Rafid name is used as an attribute of the an element, so it could occur in DOM code.
2nd Feb 2020, 1:45 PM
JS LOVER
JS LOVER - avatar
0
Use the camel case to indicate a variable. For example, the "userName". This technique will permanently eliminate such errors
2nd Feb 2020, 6:41 PM
Alexander Lebedev
Alexander Lebedev - avatar