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 Arrays Store Multiple Values in an Array Create an Array

Angelica Islas
Angelica Islas
4,082 Points

Why is this wrong?

script.js
const data = ['100',
              '80', 
              '60'
             ];

A related question: How do you decide whether you will use var, let or const when naming an array?

Sean Fallon
Sean Fallon
7,778 Points

From what I can tell it is not wrong. When I call the array positions it works fine.

const data = ['100',
              '80', 
              '60'
             ];

             console.log(data[0])

2 Answers

About your question about var, let and const when naming an array:

1) If you do not have to reassign the array -> use const! (and in most cases you do not have to reassign, you just use methods to change the content of the array)

2) If for some reason you have to reassign an array then you would use let! (i am absolutely sure there are cases when you may want to do so, but i actually could not come up with an example)

So, in most cases you will use const for arrays.

About your original question:

You stored strings inside of your arrays, not numbers (as asked in the task)... ;-)

Take away the ' at the beginning and end of each number and you will pass.

Blessings from Berlin and happy java-scripting, Nils

PS: If my answer helped you or solved your issues, please upvote my answer and/or mark it as "Best answer" (so people browsing the community forum know your issue is solved)