Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

ixtepec
ixtepec
19,347 Points

FRONT END WEB DEVELOPMENT

  1. Code Challenge: Getting & Setting

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

<script>
      var myArray = ["sugar", "rush", "fix", "it", 3.14, 42];

      var thirdElementInArray = myArray[2];

      var myArray[30] = "treehouse";
</script>

When I submit the above code I get this message:

Oops! It looks like Task 1 is no longer passing. I didn't changed anything from the previous task!

1 Answer

James Barnett
James Barnett
39,199 Points

Here's your issue:

 var myArray[30] = "treehouse";

You already declared myArray you don't want to re-declare it using var you want to assign a new value, so in this case the var keyword throws a syntax error.

ixtepec
ixtepec
19,347 Points

Thanks James!!

Sometimes the obvious is "ignored". Lesson learned!!

Thanks again for your help.