Help putting Images in an Array. JavaScript
Go to solution
Solved by vorticalbox,
What happened to you using an array of dictionaries (key->value) to store all your data? Seeing as you have multiple arrays why bother with the ['name'] part?
deer[0] = 'name'
count[0] = 0
image[0] = 'image.jpg'
each number [0] would be the same in across all arrays.
You should also probably start learning OOP and make some classes.
function Deer(name, image){ this.name = name; this.counter = 0; this.image = image; } Deer.prototype.count = function(){ this.counter += 1; }; Deer.prototype.message = function(message){ document.writeln(message); document.writeln("<img src='" + this.image + "'>") } var blitzen = new Deer('blitzen','image.jpg') var comet = new Deer('comet','comet.jpg') //count on blitzen blitzen.count(); //blitzen message blitzen.message('That red nose guy sucks :('); //count comet comet.count(); //message from comet comet.message('Blitzen eats SO much');
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now