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 JavaScript Foundations Arrays Getting and Setting

Brian CI
Brian CI
28,971 Points

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

Is there a bug in this challenge? I changed nothing in the first task yet trying to complete the third one causes it to fail.

Oops! It looks like Task 1 is no longer passing.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Arrays</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Arrays: Getting and Setting</h2>
    <script>
      var myArray = ["sugar", "rush", "fix", "it", 3.14, 42];
      var thirdElementInArray = myArray[2];
      var myArray[30] = "treehouse";

    </script>
  </body>
</html>

6 Answers

Try submitting it without the var keyword like below. This will add it to the existing array

myArray[30] = "treehouse";
Rachel Foster
Rachel Foster
6,641 Points

When I do this, I get: "Bummer! The 'myArray' length is 6 not 31."

Brian CI
Brian CI
28,971 Points

D'oh. I should have seen that :(

Jason Mc Dermott
Jason Mc Dermott
11,496 Points

I've put the answer in and it keeps changing like what Rachael here got ?? when you put in 31 its wrong and says its 32, so you put that in and its wrong again and goes to 33 and on and on..???... c'mon guys fix the glitch!

Yves Roulin
Yves Roulin
4,452 Points

Dont forget Arrays are 0 index, and 1 means 0, 2 means 1, 3 means 2 etc...

Maybe that can help someone here.

Thanks

Jason Mc Dermott
Jason Mc Dermott
11,496 Points

Thanks Yves I'm more've a HTML CSS guy but I'm getting the ropes..slowly ;)

Yves Roulin
Yves Roulin
4,452 Points

We all are learning, and thanks! Im glad i could help you! :D