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 Methods: Part 3

Can't .push("dog") at the end of .concat()

The assignment asks to concat first and second arrays and add "dog" to the end. I can't seem to get it to work. Any ideas?

var first =  ["The", "quick", "brown", "fox", "jumps"]
var second =  ["over", "the", "lazy"];
var saying = first.concat(second); 

Also, I used the three backticks to post the code, but either it's not working or I didn't do it right.

You nearly formatted your Markdown correctly. You need an empty line between the backticks and your previous paragraph. You can press edit and look at your post to see how I changed it.

4 Answers

Hi Ron,

.concat() can take multiple arguments.

So you can do this: var saying = first.concat(second, "dog");

Try adding this after the code your wrote!

saying.push( "dog" );

This will add dog to the end of the saying array, which is a combination of the first and second array.

Thanks for the correction Erik. I get it now. Unfortunately, your suggestion didn't work for me.

var saying.push("dog") = first.concat(second); 

I ended up going with Jason's suggestion, which worked.

var saying = first.concat(second, "dog");

Thanks guys!

This is how the code I was suggesting would have looked:

var first =  ["The", "quick", "brown", "fox", "jumps"]
var second =  ["over", "the", "lazy"];
var saying = first.concat(second); 
saying.push( "dog" );

Which works, but I agree Jason's suggestion is the right choice for this situation :)

Ah, yeah, I thought that's what you might have meant but didn't know if the site would accept adding another line or not, causing the system to go into conniptions. But thanks again. Much appreciated.