Can someone help me correct this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can someone help me correct this code?

I am having trouble with objects and constructors in JavaScript. Coukd someone help me fix this code such that it wouldn't return undefined? Thanks!

17th Oct 2018, 10:53 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
7 Answers
+ 6
for (let x in a){ alert(a[x].name) }
18th Oct 2018, 1:24 AM
Calviղ
Calviղ - avatar
+ 4
Ulisses Cruz here I attached it. I forgot to send it in the rush of trying to answer a challenge
17th Oct 2018, 11:39 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
Oh my gosh I forgot silly me silly me. https://code.sololearn.com/WjTYG7QhaJFz/?ref=app
17th Oct 2018, 11:39 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
just turn out "x.name" to "a[x].name" or use the for..of loop: for (let x of a){ alert(x.name) }
17th Oct 2018, 11:53 PM
MO ELomari
MO ELomari - avatar
+ 2
Just change this: for (let x in a){ to this: for(let x of a){ in other words, change 'in' to 'of'.
17th Oct 2018, 11:53 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
function Person(name, ...correct){ this.name=name this.correct=correct } var a = [ new Person("Hi",7,1,2,3), new Person("Bye",1,3,4,2)]; for (let x of a){ alert(x.name) result Hi on first window Bye on second window
18th Oct 2018, 1:50 AM
BroFar
BroFar - avatar
0
where is the code?
17th Oct 2018, 11:35 PM
Ulisses Cruz
Ulisses Cruz - avatar