Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
Is it possible that I have two different object types in this dictionary? The face cards are printing differently in the console and I don't know why

Hi I'm a student and I'm trying to make a deck of cards that contains objects for each card in the deck. I ran into a problem when linking the image file name to the face cards and here is my solution. It works, but the problem is that the face cards are now formatted differently in the console than the number cards. I'm worried that this may cause problems in my code later on. Is there a reason for this?? Thanks

var deck = [];
//initalizes variables

function createDeck(){
    class Card {
        constructor(rank, suit, img) {
            this.rank = rank;
            this.suit = suit;
            this.img = `images/${rank}_of_${suit}.png`
        };
    };

    let suits = ["hearts", "spades", "diamonds", "spades"];
    
    for (let i = 0; i<suits.length; i++){
        for (let x = 1; x<=13; x++){
            let newCard = new Card(x, suits[i])
            deck.push(newCard);
        }
    };

    function faceCard(face){
        let faceRanks= {
            1: 'ace',
            11: 'jack', 
            12: 'queen',
            13: 'king', 
        };
        face.img= `images/${faceRanks[face.rank]}_of_${face.suit}.png`;
    };

   for (let i=0; i<deck.length; i++){  
       if (deck[i].rank==1 || deck[i].rank>10) faceCard(deck[i]);
    }
 
};
createDeck();
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda