I'm new to javascript so I figured I would starts something completely out of my league.(Trial by fire) I'm working on a texted based combat system for a game using javascript. I'm trying to reference an object property from a function.
I've tried including the document.getElementById withing the object property and referencing it as a function with the object.
This is the first set I tried
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
var creature = {
name: "Creature",
description: "Discription goes here.",
health: 20,
damage: document.getElementById('damageObject').innerHTML = randomNumber(4,8)
}
and this is the second
var creature = {
name: "Creature",
description: "Discription goes here.",
health: 20,
damage: creatureDamage(3,7)
}
function creatureDamage(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
In both cases I'm trying to create a property that can change the range of values in a Math.random based function. ex(max * min)
In the first one, I was trying to create the object "creature" and create the properties: name, description, health, and damage. Within the damage property, I was trying to provide information to the function randomNumber. No information is pulled and I'm not sure what to add to reference the information needed.
In the second one, I tried creating the function creatureDamge and referencing it within the damage property. This was to create a specific function for that specific creature instead of trying to create a function that I could use across multiple different creatures. When running the second one, it was still not pulling the information to the function from the object.
damageto be a function?creatureDamageI want it to pull the min and max numbers for the Math.random range. I might be over complicating this.