Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKevin Ohlsson
4,559 Pointsstudents.lenght = undefined
Hello
this does not work:
for (let i = 0; i < students.lenght; i++) {
let stuObj = students[i];
let datas = `<h1>${stuObj.name}</h1>`
datas += `<p>${stuObj.track}</p>`
datas += `<p>${stuObj.achievements}</p>`
datas += `<p>${stuObj.points}</p>`
print(datas)
}
function print(arg) {
document.write(`<div> ${arg} </div>`)
}
but this does
for (let i = 0; i < 5; i++) {
let stuObj = students[i];
let datas = `<h1>${stuObj.name}</h1>`
datas += `<p>${stuObj.track}</p>`
datas += `<p>${stuObj.achievements}</p>`
datas += `<p>${stuObj.points}</p>`
print(datas)
}
function print(arg) {
document.write(`<div> ${arg} </div>`)
}
why does students.lenght return undefined?
let students = [
{
name: "Kevin",
track: "JavaScript",
achievements: "123",
points: 3500,
},
{
name: "John",
track: "LUA",
achievements: "312",
points: 2121
}]
3 Answers
Gia Gabadadze
1,794 Pointsyou are using students.lenght you should use students.length
for (let i = 0; i < students.length; i++) {
let stuObj = students[i];
let datas = `<h1>${stuObj.name}</h1>`
datas += `<p>${stuObj.track}</p>`
datas += `<p>${stuObj.achievements}</p>`
datas += `<p>${stuObj.points}</p>`
print(datas)
}
function print(arg) {
document.write(`<div> ${arg} </div>`)
}
Alexander Davison
65,469 PointsTry students.length
(notice the 's')
Kevin Ohlsson
4,559 Pointsundefined
for (let i = 0; i < students.lenght; i++) {
let stuObj = students[i];
let datas = `<h1>${stuObj.name}</h1>`
datas += `<p>${stuObj.track}</p>`
datas += `<p>${stuObj.achievements}</p>`
datas += `<p>${stuObj.points}</p>`
print(datas)
}
function print(arg) {
document.write(`<div> ${arg} </div>`)
}
not misspell
John Gilmer
Courses Plus Student 1,806 PointsTry student.length
Kevin Ohlsson
4,559 PointsUncaught ReferenceError: student is not defined