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

Jesse Gonzalez
Jesse Gonzalez
7,322 Points

const not working but let is (ARRAYS)

I've noticed the push and unshift was not adding it and showing in the console. I changed it to LET and it showed all 8.

let instruments = ['piano', 'drums', 'trumpet']; instruments.push( 'guitar', 'violin', 'triangle' ); instruments.unshift( 'cowbell', 'tuba');

is there something I did wrong? thanks in advance!

Hi Jesse,

Is this question in response to a specific video on here?, is so please can you provide the link and I will take a further look.

I tried the above code you provided and it worked fine in Chrome Dev Tools console as you say, so perhaps if you could provide the example that did not work, and I could look at that also to try and help.

let instruments = ['piano', 'drums', 'trumpet'];
instruments.push( 'guitar', 'violin', 'triangle' );
instruments.unshift( 'cowbell', 'tuba');

I also tried it using a const and this worked:

const instruments = ['piano', 'drums', 'trumpet'];
instruments.push( 'guitar', 'violin', 'triangle' );
instruments.unshift( 'cowbell', 'tuba');

1 Answer

Jesse Gonzalez
Jesse Gonzalez
7,322 Points

Oh yes, not sure why it didn't tag the course. It was "adding to arrays". I tested both const and let and I have came to the conclusion that most likely I spelled "const" wrong and it wasn't reading it. Thanks for the info!

Ahhhh no worries, yes this is usually the cause of most errors when coding, I still do this a lot :D