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

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.