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
Deontre Jones
Courses Plus Student 2,625 PointsArray code Code Challenge isn't working
On about line 18, set the 31st element in 'myArray' to the word 'treehouse'.
Here's my answer:
var myArray[31] = "treehouse";
for some reason the problem wont go through, it keeps saying now I have problem 1 wrong, which does not make any sense. Can someone please help?
8 Answers
Stone Preston
42,016 Pointsthe 31st element is actually the 30th index since arrays indexes start at 0, so setting myArray[31] is incorrect because it isnt setting the 31st element, its setting the 32nd
laurie gloge
8,593 PointsStill no luck... var myArray = ["sugar", "rush", "fix", "it", 3.14, 42]; var thirdElementInArray = myArray[2]; var myArray[30] = "treehouse";
Stone Preston
42,016 Pointsoh its because you have var in front of myArray[30]. remove that so you should have:
myArray[30] = "treehouse";
if you put var in front it defines a new myArray variable, which means task 1 no longer passes since it doesnt hold the same value
Joe Williams
4,014 PointsTaking away the var worked for me, Stone Preston, but I'm still not sure why that worked. Could you explain why keeping the var makes task 1 not pass?
evansimoni
4,542 PointsI am having an issue as well. I typed out my code using the 30 value instead of 31 but I am recieving the error that Task 1 is no longer passing. Any advice for what may be causing the problem?
Walter Correia
4,642 Points//about about getting rid of the var should look like this: myArray[30] = "treehouse"; it worked for me
evansimoni
4,542 PointsThat worked! Thank you. Makes sense too, there's no need to define a variable there.
Spencer Dixon
7,371 PointsIts not working for me either. It says that the first one is no longer working now. I tried getting rid of the "var" in the third line but still doesnt work.
var myArray = ["sugar", "rush", "fix", "it", 3.14, 42]; var thirdElementInArray = myArray[2]; var myArray(30) = "treehouse";
Spencer Dixon
7,371 Pointsnevermind was using the wrong kind of brackets () vs. []
laurie gloge
8,593 PointsI too am getting the response Task one is no longer passing. with this answer ...
var myArray = ["sugar", "rush", "fix", "it", 3.14, 42];
var thirdElementInArray = myArray[2];
var myArray[30]='treehouse';
I also tried... var myArray[30] = "treehouse"
Stone Preston
42,016 Pointsit could be your use of single quotes. try using double quotes
var myArray[30] = "treehouse";
laurie gloge
8,593 PointsThanks, that fixed it! Yeah!
Alexandre Ribeiro
29,091 PointsHey everyone,
It seems like we are not suppose to define a VARIABLE because it is already there! We only need to define a VALUE for the 31st element in the array:
myArray[30] = 'treehouse';