+ 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!
7 ответов
+ 6
for (let x in a){
alert(a[x].name)
}
+ 4
Ulisses Cruz here I attached it. I forgot to send it in the rush of trying to answer a challenge
+ 3
Oh my gosh I forgot silly me silly me.
https://code.sololearn.com/WjTYG7QhaJFz/?ref=app
+ 3
just turn out "x.name" to "a[x].name" or use the for..of loop:
for (let x of a){
alert(x.name)
}
+ 2
Just change this:
for (let x in a){
to this:
for(let x of a){
in other words, change 'in' to 'of'.
+ 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
0
where is the code?