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 trial

JavaScript JavaScript Foundations Arrays Getting and Setting

setting 31st element of a 6-element array to a value - not working - help?

Challenge task 2 of 2 "On about line 18, set the 31st element in 'myArray' to the word 'treehouse'."

  var myArray[30] = 'treehouse';

Result: "Oops! It looks like Task 1 is not passing..."

How is my entry incorrect and how can I fix it?

Thanks in advance.

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Chris,

The keyword var in front of the assignment shouldn't be there, you only need to use var when declaring variables but don't need to when you're assigning a value back to them.

this seems to work.

myArray[30] = 'treehouse' ;

Thanks! Removing var worked. :)