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

You have a few things wrong: listPhotos.push should be this.listPhotos.push You should be pushing the variable x and not the string x When logging you want this.listPhotos and not x.listPhotos function Album() { this.listPhotos = [“bee”, “ladybug”, “caterpillar”, “ant”]; this.addPhoto = function(x) { this.listPhotos.push(x); console.log(this.listPhotos); } } let a = new Album() a.addPhoto(‘123’)

What is wrong with this function

When you wrote: function lоаd(){ аlert(‘Hello!’); } You used: U+006C : LATIN SMALL LETTER L U+043E : CYRILLIC SMALL LETTER O U+0430 : CYRILLIC SMALL LETTER A U+0064 : LATIN SMALL LETTER D When you wrote: window.onload = load; You used: U+006C : LATIN SMALL LETTER L U+006F : LATIN SMALL LETTER O U+0061 : … Read more