0

Can someone please explain this?

// above is function(){ // var names=[ ] // } function array(){ var i=0 var j=0 var k=0 var l=0 var m=0 window.names[i] = document.getElementById("subject").value; i++; document.getElementById("subject").value = ""; It says error cant set property '0' of undefined. I cant tell where the error is. https://code.sololearn.com/WgyjaJ3BwMOr/?ref=app https://code.sololearn.com/WgyjaJ3BwMOr/?ref=app https://code.sololearn.com/WgyjaJ3BwMOr/?ref=app

24th Jul 2020, 8:54 AM
Tri Satria [FIRST]
Tri Satria [FIRST] - avatar
5 Answers
+ 2
That's because window.names is not defined. By the way, a lot of semicolons in the code are missing.
24th Jul 2020, 10:44 AM
Javier Ballesteros
Javier Ballesteros - avatar
+ 2
You should be careful, because variables defined locally in a function won't be available outside of it.
24th Jul 2020, 10:47 AM
Javier Ballesteros
Javier Ballesteros - avatar
+ 1
It doesnt matter whether i use semicolon or not in javascript. But i have no idea why it doesnt work where as i used window.names to call variable names inside another function.
24th Jul 2020, 11:00 AM
Tri Satria [FIRST]
Tri Satria [FIRST] - avatar
+ 1
Yes, but the problem is that you declared the variable inside a function. You should do it outside it. Same with verbs, nouns and the rest of it.
24th Jul 2020, 11:25 PM
Javier Ballesteros
Javier Ballesteros - avatar
0
Thx very much but ive done the project!
25th Jul 2020, 1:58 AM
Tri Satria [FIRST]
Tri Satria [FIRST] - avatar