lundi 27 juillet 2020

Why does this if statement return empty strings? Javascript card game [closed]

I want each card in the deck to have a digitValue assigned. I ran this loop on the deck array and while numbers two to ten are assigned the correct digitValue (corresponding number), the royal cards and ace are being assigned as empty strings rather than the letter I'm trying to assign.

export function calculateDigitValue(deck) {

    for (let i = 0; i < deck.length; i++) {

        if (
        deck[i].value == 'two' ||
        deck[i].value == 'three' ||
        deck[i].value == 'four' ||
        deck[i].value == 'five' ||
        deck[i].value == 'six' ||
        deck[i].value == 'seven' ||
        deck[i].value == 'eight' ||
        deck[i].value == 'nine' ||
        deck[i].value == 'ten') {
            deck[i].digitValue = (wordsToNumbers(deck[i].value)).toString();
        }
         else if (deck[i].value === 'king') {
            deck[i].digitValue === 'K';
         } else if (deck[i].value === 'queen') {
             deck[i].digitValue === 'Q';
         } else if (deck[i].value === 'jack') {
            deck[i].digitValue === 'J';
         } else if (deck[i].value === 'ace') {
             deck[i].digitValue === 'A';
         }
    }
}

Here is an example of a card object from the deck array after running this loop:

1: {value: "jack", suit: "clubs", cardName: "jack_clubs", attackValue: 10, digitValue: ""}

Aucun commentaire:

Enregistrer un commentaire