Can someone please explain me why this happened? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone please explain me why this happened?

HELLO I’M TRYING TO LEARN JAVASCRIPT AND THIS IS SIMPLE BUT I CAN’T UNDERSTAND WHY IN THIS FOR THE ARRAY DOES NOT START IN THE FIRST INDEX: let friends = [“John”, “Peter”, “Nancy”]; for(var I = 0; I<friends.length; I++){ document.getElementById(‘div’).innerHTML = amigos[I]; }

11th Jul 2020, 9:46 AM
Oliver Reyes
Oliver Reyes - avatar
3 Answers
+ 2
if i'm right its only showing Nancy to print them all try using += amigod[I] instead of = amigos[I]
11th Jul 2020, 9:50 AM
Taste
Taste - avatar
+ 2
Your array is named <friends>, but you try to access <amigos> which is undefined. I'm guessing you meant `friends[i]` instead of `amigos[i]` there.
11th Jul 2020, 10:15 AM
Ipang
0
man thank’s
11th Jul 2020, 9:52 AM
Oliver Reyes
Oliver Reyes - avatar