Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda