sei-ec-remote / project-1-issues

Open new issues here
1 stars 2 forks source link

Can't push objects to an array #167

Closed smsgoldberg closed 1 year ago

smsgoldberg commented 1 year ago

What's the problem you're trying to solve?

I'm trying to push objects I created into an empty array so I can use them to populate the board, but I keep getting a "push is not defined" error. The array in question is defined at the top of my code.

Post any code you think might be relevant (one fenced block per file)

/*-----constants -----*/
//we will keep all our images in an image array - and randomize their positioning everytime the game is initialized
const imageArray = [];
const matchArray = imageArray.map((x) => x * 1);
const mergedDogArray = imageArray.concat(matchArray);

//objects

class dog {
    constructor(number, backgroundColor) {
        this.number = number;
        this.backgroundColor = backgroundColor;
    }
}

const swimmingDog = new dog(1, 'blue');
imageArray.push(swimmingDog);

const smilingDog = new dog(2, 'green');
imageArray.push(smilingDog);

const puppyDog = new dog(3, 'yellow');
imageArray.push(puppyDog);

const olderDog = new dog(4, 'red');
imageArray.push(olderDog);

const sleepingDog = new dog(5, 'purple');
imageArray.push(sleepingDog);

const jumpingDog = new dog(6, 'white'); 
imageArray.push(jumpingDog);

const ballDog = new dog(7, 'black');
imageArray,push(ballDog);

const runningDog = new dog(8, 'orange');
imageArray.push(runningDog);

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

main.js:87 Uncaught ReferenceError: push is not defined at main.js:87:12

What is your best guess as to the source of the problem?

I'm genuinely not sure it the problem here is logical or syntactical in nature -- which makes me suspect it's a combination of the two.

What things have you already tried to solve the problem?

I've tried putting the color names -- included only for my own testing purposes -- in single quotes. Otherwise I'm quite flummoxed and have been for quite a while.

Paste a link to your repository here

https://github.com/smsgoldberg/StayGolden

asands94 commented 1 year ago

Is the push is not defined message happening on the very first line where you try to push into your new array or later on? Also you have a comma on the second to last imageArray you are trying to push into

smsgoldberg commented 1 year ago

I totally missed the comma! It's not throwing that error anymore.