I made two function factories, one for zombies, one for humans. I want to have a function that takes the difference between the total zombie health versus total human attack. It works with one each, but I cant wrap my head around how to do multiple humans versus zombies. I have tried pushing the human objects to an array so that I could sum all the attack(i would repeat for zombies), but no luck...
//Create a Human spawning object
var humanArr = [];
const humanSpawns = (attack) => {
let human = {
attack: attack
};
humanArr.push(human);
};
//Create a Zombie spawning object
const zombieSpawns = (health) => {
return {
health: health
}
};
//Create function to have humans and zombies fight
function fight() {
var result = humanOne.attack - zombieOne.health;
if(result > 0) {
document.write('Live to see another day.');
} else {
document.write('The zombies are taking over!');
}
}
const zombieOne = zombieSpawns(12);
const humanOne = humanSpawns(11);
fight();