I have been creating a pokemon stat calculator using html, css and javascript for my personal use. The code mostly works and my issue is based specific part of it.
var Natures = { 'Adamant':{'pos':'Atk', 'neg':'SpA'} }
Above is a sample of an object that stores data on natures(each nature boosts one stat by 10% and reduces another by the same amount). The nature values are objects with properties that represent the stats they are boosting and reducing. My issue is with the following piece of code:
if(Natures.hasOwnProperty(nature)) {
var plus = eval(Natures.nature['pos']);
var minus = eval(Natures.nature['neg']);
base.plus = Math.floor(base.plus*1.1);
base.minus = Math.floor(base.minus*0.9);
}
The if statement is inside a function that modifies an object (base) and outputs its values (one for each of the 6 stats). The if statement checks the Natures object for a specific nature (a string given as a function parameter).
After some tests, I'm sure that the if statement is working. The issue lies with the next two lines. They are meant to access the pos and neg values for the nature and store them as plus and minus. The eval() is there so I can use plus and minus to access and modify the appropriate values of the base, which are not strings.
I've checked around and don't see any problems with my syntax. I'm also sure that I've isolated the problem in the code I've posted above. The function runs fine with nature isn't in Natures. Also, I've only been testing this in Chrome (Version 40.0.2214.115) so it might be the browser.