Skip to content
Advertisement

JavaScript – Child objects called by functions to update child objects

I am learning about objects and their scopes, I got confused and decided to make a D&D pathfinder character sheet for practice.

I made the character sheet as an object, child objects for ability scores, strength/dexterity/intelligence/etc… and then base and modifier values.

in D&D you use your base value to calculate your modifier value and the modifier is used throughout the game. The calculation for modifier is (base - 10) / 2

as i run this i only get 0 when called console.log(characterSheet.abilityScore.strength.modifier)

I assume my confusion is about my understanding of the scope range between the function and modifier/base. but I’m not sure where to start.

JavaScript

I have also tried placing the function in the global scope but always returns NaN.

JavaScript

Advertisement

Answer

you can use that… ?

JavaScript

OR:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement