How to write a function that takes an argument and adds it to an array? [closed]

You have a few things wrong:

  1. listPhotos.push should be this.listPhotos.push
  2. You should be pushing the variable x and not the string x
  3. When logging you want this.listPhotos and not x.listPhotos
function Album() {
  this.listPhotos = ["bee", "ladybug", "caterpillar", "ant"];
  this.addPhoto = function(x) {

let a = new Album()

Browse More Popular Posts

Leave a Comment