I need help with the following exercise: It is an exercise using JS in the browser console, I have 3 cards, I have to create a function and add them with the following condition, if the card is a 1 value of 20 and if it is a red card it is worth twice its value.
carta1 = {PALO:"c",VALOR:1}
carta2 = {PALO:"d",VALOR:7}
carta3 = {PALO:"p",VALOR:5}
cartas = [carta1,carta2,carta3];
function puntua(){
var mano = 0;
for (var i = 0; i < cartas.length; i ++) {
if (cartas[i].VALOR === 1) {
cartas[i].VALOR = 20;
}
if (cartas[i].PALO === "d" || cartas[i].PALO === "c") {
cartas[i].VALOR = cartas[i].VALOR*2;
}
for (var i = 0; i < cartas.length; i ++) {
mano = mano + cartas[i].VALOR;
}
}
console.log(mano);
}
puntua();
As a result I get 52, I suppose that 1 of hearts is giving it to me as 40 because 1 is worth 20 and being red is worth double, but I do not know why the other 2 cards are only 5 and 7 when the 7 that is a "d" I would have to add it to 14, someone can tell me what is wrong in my code