Build a Shopping List - Step 14

Tell us what’s happening:

I have the shoppingList array with what “should now have 5 items in it”. It looks like I did pop to the array.
At the bottom it says “shoppingList” is read-only.

What am I inputting wrong here?

Your code so far

console.log("Grocery shopping list");

const shoppingList = [];

console.log("It will be nice to have some fruit to eat.");

shoppingList.push("Apples");

function getShoppingListMsg(arr) {
  return `Current Shopping List: ${arr}`;
}

console.log(getShoppingListMsg(shoppingList));

shoppingList.push("Grapes");
console.log(getShoppingListMsg(shoppingList));

console.log("It looks like we need to get some cooking oil.");

shoppingList.unshift("Vegetable Oil");
console.log(getShoppingListMsg(shoppingList));

shoppingList.push("Popcorn", "Beef Jerky", "Potato Chips");
console.log(getShoppingListMsg(shoppingList));

console.log("This looks like too much junk food.");


// User Editable Region

shoppingList = ["Vegetable Oil", "Apples", "Grapes", "Popcorn", "Beef Jerky"];
shoppingList.pop();

console.log(shoppingList);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Build a Shopping List - Step 14

Hi @jt5487

What is an issue when declaring a variable with const?

Happy coding

the error that shoppingList is read-only comes from here

Hey, nah that’s what the site already has it set as. I did try setting it to let instead, but no difference. Since it doesn’t change, figure const makes sense.

const isn’t a problem, but if it’s const you cannot re-assign the variable to a NEW array.

Luckily, the instructions do not ask you to do that.

The instructions are only this:

Use the pop method to remove the last item from the shoppingList array.

Exactly.
I figured it out, wasn’t working originally for some reason. But realized I didn’t have all the info in my array for it to pass so Beef Jerky was getting the pop instead of the non present Potato Chips.
Thanks everybody

1 Like

The problem was that you were trying to reassign a const variable.

If you add Potato Chips to that assignment, you still get a read-only message.

shoppingList = ["Vegetable Oil", "Apples", "Grapes", "Popcorn", "Beef Jerky", "Potato Chips"];

TypeError: "shoppingList" is read-only

Glad you got it though

1 Like