0

I'm trying to figure out how to make the following code work:

     <ul> <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", "defense", 10, event.button);'>+10 Defensive Ability</li> <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", "[\"defense\", \"constitution\"]", [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> </ul>

These links are accessing methods from the the star object. I need the 2nd and 3rd parameters to be arrays, because they have a variable number of values. For instance, the first star, anvil1, has one stat (defense) and one value (10). The fourth star has two stats (defense, constitution) and two values (10, 20). I believe the number of stats/values can go up to 3.

So far, if I try to call stats[0] the value that's returned is simply the first letter?

alert('Stats: ' + stats[0]); results in an alert box with Stats: d I'm not sure how to fix this, and any advice would be greatly appreciated!

3
Contributors
4
Replies
21
Views
1 Year
Discussion Span
Last Post by diafol
0
<ul> 
  <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", "defense", 10, event.button);'>+10 Defensive Ability</li>
  <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", "[\"defense\", \"constitution\"]", [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> 
</ul>
0

I was sending a string instead of an array. Solution:

<ul> 
  <li id='anvil1' class='locked' onclick='anvil1.countCheck("anvil1", ["defense"], [10], event.button);'>+10 Defensive Ability</li>
  <li id='anvil4' class='locked' onclick='anvil4.countCheck("anvil4", ["defense", "constitution"], [10, 20], event.button);'>+15 Defensive Ability <br />+20 Constitution</li> 
</ul>
0

Instead of sending 2 arrays, you could send one object:

["defence"],[10] could be ONE var: {"defence": 10}
["defence","constitution"],[15,20] could be ONE var: {"defence": 15, "constitution": 20}

Then you don't need a check to see if lengths of the two arrays are equal.

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.