Ask coding questions

← Back to all posts
help with exercise 2 in JS Assignment 10: Array Properties and Methods
HannahB593 (2)

I'm really stuck on this question- the rest i understand and have correctly. Just not sure what's wrong with two.

This is what I have:

function exerciseTwo(snacks){
let favoriteSnack= 'grapes';
snacks.push = (favoriteSnack (or grapes?) ;
return snacks;

before i added "let favoriteSnack" i had gotten the error saying "grapes is undefined."- so that's why i tried to use that. been looking for clues but unsure- can anyone help ?

Highwayman (1358)

Snacks.push(favoriteSnack); maybe instead of snacks.push = (favoriteSnack); ?
Edit: or snacks.push('grapes');

mwilki7 (1105)

@Highwayman the first one is correct i think

Giothecoder (130)

@mwilki7 I’m pretty sure they want something like the second though.

because look he says 'grapes' and never makes the var?

HannahB593 (2)

excellent! This worked, thank you. That makes sense considering unshift has 1 in exercise 4 for example, which is just in parentheses just like 'grapes' is in this exercise. @Highwayman