I'm trying to get the variable with the winner
. I ask for the highest number but how get I get the according player / variable name
:
var A = 0;
var B = 0;
var C = 0;
var D = 0;
var E = 0;
var F = 0;
var G = 0;
var H = 0;
$('.answer').on('click', function (evt) {
const types = $(this).data("typ").split(" "); // split on space.
const active = $(this).is('.active');
types.forEach(typ => {
if (active) {
window[typ]--
} else {
window[typ]++
}
})
console.log(A,B,C,D,E,F,G,H)
$(this).toggleClass("active");
});
$('.fin').on('click', function (evt) {
var players = ['playerA': A, 'playerB': B,'playerC': C,'playerD': D,'playerE': E,'playerF': F,'playerG': G, 'playerH': H];
var winner = Math.max.apply(null, players );
alert(winner, 'wins');
});
Thanks in advance!