Switching Variable in Child Row with Const
Switching Variable in Child Row with Const

So in one of my child rows, I've got a variable that will output a number. This number, I am trying to compare to data in a const and output the matching one in place of the original variable (in my case, round.number). Its stumping me a bit bc of how its within a child row of datatables. Here is an example showing the child rows:
http://live.datatables.net/zavoloqo/2/edit
And this is the const that I'm trying to use to compare/replace with round.number to const number as shown below:
// Index of 0 to 51 : ♦2 to ♣A ( ie. '4' equates to ♦3 )
const CARDS = [
♦2, ♥2, ♠2, ♣2, ♦3, ♥3, ♠3, ♣3, ♦4, ♥4,
♠4, ♣4, ♦5, ♥5, ♠5, ♣5, ♦6, ♥6, ♠6, ♣6,
♦7, ♥7, ♠7, ♣7, ♦8, ♥8, ♠8, ♣8, ♦9, ♥9,
♠9, ♣9, ♦10, ♥10, ♠10, ♣10, ♦J, ♥J, ♠J,
♣J, ♦Q, ♥Q, ♠Q, ♣Q, ♦K, ♥K, ♠K, ♣K, ♦A,
♥A, ♠A, ♣A
];
// Game event translation ( output from round.number = CARDS[Math.floor(float * 52)] )
const number = CARDS[Math.floor(float * 52)];
This question has an accepted answers - jump to answer
Answers
If I understand your question correctly you can access the elements in the CARDS array with
CARDS[ round.number ]
. Just make sure CARDS is a global variable or within the scope of the format() function.Kevin
It seems like any time I try to add the CARDS array anywhere it breaks datatables. Any ideas why this might be? Sorry the end const number = CARDS[Math.floor(float * 52)]; doesn't apply to this question.
Essentially in my example, the number is 34 so I'm trying to display ♠10 as its 34 within the index.
The problem is more likely CARDS is an array of strings but you don't have quotes around them. Should look more like this:
You are probably getting a syntax error in your browser's console.
Kevin
That fixed it - dunno how I missed that, lol. Thanks for the second set of eyes!
Oh one other thing - when I use CARDS[round.number], it will output the proper card if there is just a single number for round number but when it outputs an array (ie. 37, 19, 3), it just shows "undefined". How would I go about displaying them for the strings?
Actually I figured this out on my own. Ended up using the following:
Perfect!
Kevin