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();