Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Jesse Gonzalez
Jesse Gonzalez
4,589 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!

Martin Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Martin Jones
Front End Web Development Techdegree Graduate 42,781 Points

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
4,589 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!