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!
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 trial

Oscar Mauricio Lancheros Murillo
3,608 PointsHi, why my program is not entering to the loop?
function sumame(arr){
console.log('Inicio del programa')
var sum = 0;
for (i=0; i < arr.lenght; i++){
console.log("Inicio del ciclo")
sum = sum + arr[i];
console.log(`Ahora sum es ${sum}`)
}
console.log(`Finalmente sum es ${sum}`)
return sum;
}
4 Answers

Steven Parker
225,652 PointsYour problem is caused by a misspelled property name.
You wrote "arr.lenght
" instead of "arr.length
".
Also, while "sum = sum + arr[i]
" is fine, you might like to know that there is a shorthand version that does the same thing: "sum += arr[i]
".

Christof Baumgartner
20,864 PointsCan you put
console.log(arr.lenght);
before the loop and tell if it shows a valid value. Or post an example array to be sure that it is valid.
Also don't omit the ";"-characters after your statements. They might cause the error as well. So write in the loop:
console.log("Inicio del ciclo");
sum = sum + arr[i];
console.log(`Ahora sum es ${sum}`);

Oscar Mauricio Lancheros Murillo
3,608 PointsIt says its undefined arr.lenght

Steven Parker
225,652 PointsThat's because of the spelling — see my answer above.

Oscar Mauricio Lancheros Murillo
3,608 Pointsyeah, is length, thank you!