Etudier le code
const cards = [];
for(let suit of ['H', 'C', 'D', 'S']) // hearts, clubs, diamonds, spades
for(let value=1; value<=13; value++)
cards.push({ suit,value });
Object.keys(cards).forEach(function (c,i) {
console.log(`carte N°${i} ${cards[c].suit}${cards[c].value}`);
});
for (let c of cards){
console.log(`${c.suit}${c.value}`);
}
let dictionnary = { 'H': '\u2665', 'C': '\u2663', 'D': '\u2666', 'S': '\u2660', 1: 'A', 11: 'J', 12: 'Q', 13: 'K'};
function cardToString({suit,value}) { //
if (!dictionnary[value]==0) value=dictionnary[value];
return value+dictionnary[suit];
}
Object.keys(cards).forEach(function(c) {
//console.log(cards[c]);
console.log(`carte ${cardToString(cards[c])}`);
});
for (let c of cards){
console.log(`${cardToString(c)}`);
}
console.log(` les cartes du paquet sont : ${cards.map(cardToString)}`);
Trouver le code pour afficher
"les figures Rouges : J♥,Q♥,K♥,J♦,Q♦,K♦"
const cards = [];
for(let suit of ['H', 'C', 'D', 'S']) // hearts, clubs, diamonds, spades
for(let value=1; value<=13; value++)
cards.push({ suit,value });
Object.keys(cards).forEach(function (c,i) {
console.log(`carte N°${i} ${cards[c].suit}${cards[c].value}`);
});
for (let c of cards){
console.log(`${c.suit}${c.value}`);
}
let dictionnary = { 'H': '\u2665', 'C': '\u2663', 'D': '\u2666', 'S': '\u2660', 1: 'A', 11: 'J', 12: 'Q', 13: 'K'};
function cardToString({suit,value}) { //
if (!dictionnary[value]==0) value=dictionnary[value];
return value+dictionnary[suit];
}
Object.keys(cards).forEach(function(c) {
//console.log(cards[c]);
console.log(`carte ${cardToString(cards[c])}`);
});
for (let c of cards){
console.log(`${cardToString(c)}`);
}
console.log(` les cartes du paquet sont : ${cards.map(cardToString)}`);
console.log(`les figures Rouges : ${cards.filter(c => c.value > 10 && (c.suit === 'H' || c.suit === 'D') ).map(cardToString) }`);