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

Steven Quinn
Steven Quinn
12,519 Points

Can somebody please give some advice with the second part of this task.

I've entered the following code but it returns the error: The 'myArray' length is 6 not 31. What am I doing wrong here?

index.html
<!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 treehouse = myArray[31];

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

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Steven,

Currently your assigning the value of an item that doesn't exist in the array to the variable treehouse which is the opposite of what you want to be doing, instead you need to update the 31st value in the array which would be 30 since arrays start at the zeroth index and assign the string treehouse as it's value.

var myArray = ["sugar", "rush", "fix", "it", 3.14, 42];
var thirdElementInArray = myArray[2];
myArray[30] = 'treehouse';

Happy coding.

Steven Quinn
Steven Quinn
12,519 Points

Thank you Chris! Think I tried something similar but didn't add the quotation marks! Still getting used to the syntax.

Chris Shaw
Chris Shaw
26,676 Points

No worries, throw as many questions as you need towards us, we're always here to help.