The title maybe is a little wrong but thats what I think the function should to to change to the right class.
So this is my problem, i have created a dice roller, that count the sum of the dices.
The thing is that the counter is images switching after the sum of the dices, and they are called by class name from zero to nine.
When i have one dice with number 5, the image 5 shows, but when i have 2 dices with sum lets say 5 + 2 image 5 and 2 shows and not 7. so the classChange wont work.
I tried to insert a element.className = ” ” but it change the variable right away since i put it in a loop. well, hard to explain so I did a jsFiddle.
The code for the counter are row between 81 and 125
function numberTotext(nr){
var arrClass=["zero","one","two","three","four","five","six","seven","eight","nine"];
ret=[];
nr=nr.toString();
for(i in nr){
ret.push(arrClass[nr[i]]);
}
console.log(ret);
return ret;
}
numberTotext(total)
function turnCounter(){
for (var i = 0; i < arguments.length; i++){
dice_toolbar_counter_wrapper_Li = createElementWithClass('li',arguments[i]);
console.log(dice_toolbar_counter_wrapper_Li)
dice_toolbar_counter_wrapper_Ul.appendChild(dice_toolbar_counter_wrapper_Li);
document.getElementById("ul");
}
} turnCounter(ret);
Remove element before appending new one when you calculate the total each time, so the counter only shows one time and not multiple times. Also you have to change CSS to make it easier to be able to calculate what class you have to use.
WORKING JSFIDDLE DEMO
Change relevant parts of CSS to:
Change JS to: