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
Veronika Benkeser
2,930 Pointsarrays challenge
Hello, Here is the error that I am receiving: Bummer! Was expecting 'thirdElementInArray' to be "fix" not "undefined"
My code: var myArray = ["sugar", "rush", "fix", "it", 3.14, 42]; myArray[2] = "thirdElementInArray";
Please help. Also, it seems like this example wants us to substitute "fix" and ""thirdElementInArray". How would we insert "thirdElementInArray" while keeping the order of the other elements intact?
Thank you!
3 Answers
Dave Levine
1,474 PointsTry reversing them. Thirdelementinarray = myarray[2]
Herbert Rosales
5,141 PointsIt depends on how you want to use it (output it) in the DOM. Currently your code looks pretty good the myArray[] values should be intact. Try the code below it should print both all of the myArray values and the one below should print just the index value of 2.
var myArray = ["sugar", "rush", "fix", "it", 3.14, 42]; alert(myArray); // prints all values
myArray[2] = "thirdElementInArray"; alert(myArray[2]); // prints only the index value of 2
I'm also new to Javascript, I hope this helps.
Veronika Benkeser
2,930 PointsThank you, guys! Got it :)
Herbert Rosales
5,141 PointsHerbert Rosales
5,141 PointsIt depends on what you want to output. Currently your code looks pretty good the myArray[] values should be intact. Try the code below it should print both "fix" and all of the myArray values.
alert(myArray[2]); alert(myArray);
I'm also new to Javascript, I hope this helps.