I have a function that looks like so:
window.attack = function(enemyHealth){
attackChance = Math.floor(Math.random()*11);
console.log("enemyHealth: "+enemyHealth); //undefined...
if (attackChance < 5) { //hit
hitDamage = Math.floor(Math.random()*playerDamage+1);
enemyHealth = enemyHealth - hitDamage;
$('#enemyhealth').val(enemyHealth);
if (enemyHealth < 1) {
alert('You killed the '+currentEnemy);
removeOverlayNow();
}
} else if (attackChance >= 5) { //miss
hitDamage = Math.floor(Math.random()*maxDamage+1);
alert('You miss and get attacked for '+hitDamage);
health = health - hitDamage;
$(healthDisplay).val(health);
checkHealth();
}
}
And my variable is being thrown in via:
onclick="flee('+currentEnemyHealth+')"
But when I console.log or alert() all I get is Undefined...
Am I missing a trick here? I thought that if I pass a variable into the function (in this case enemyHealth), that I should be able to retrieve it?
Thanks.
p.s.
Just thought I would state that even if I pass a card-coded number (such as 5) through the function - it still arrives as Undefined