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

arrays 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!

It 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.

3 Answers

Try reversing them. Thirdelementinarray = myarray[2]

It 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.

Thank you, guys! Got it :)