I need to add +1 to each card clicked but
Function result 3 as undefined why? what is wrong with my code?
card2 and card3 function recive each variable inside each click function
inside function click2 setcard(card2); click3 setcard(card3); and so on
For some reason it do not work.
var card2 = 0;
var card3 = 0;
function setcard(card2, card3) {
document.getElementById("truecount").innerHTML = card2 + card3;
}
//functions
function clickplus2() {
resultado += 2;
zen += 2;
cartas += 1;
valor += 2;
zenok += 11;
card2 += 1;
setresultado(resultado, zen, cartas, valor, zenok);
setcard(card2);
}
function clickplus3() {
resultado += 3;
zen += 2;
cartas += 1;
valor += 3;
zenok += 10;
card3 += 1;
setresultado(resultado, zen, cartas, valor, zenok);
setcard(card3);
}
card2andcard3insetcardshadow the global variables, so if you don't pass a second argument tosetcard()when you call it, it will always beundefinedsetcard(card2, card3)should be like this?setcard(card2, card3)or remove the parameters fromsetcard(), so it uses the global variables.letorconstinstead ofvarto declare variables.undefined... since you don'treturnany value in any of your fuctions, this is as expected