-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday73.js
47 lines (40 loc) · 798 Bytes
/
day73.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** @format */
// program to shuffle the deck of cards
// declare card elements
const suits = ['Spades', 'Diamonds', 'Club', 'Heart'];
const values = [
'Ace',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'10',
'Jack',
'Queen',
'King',
];
// empty array to contain cards
let deck = [];
// create a deck of cards
for (let i = 0; i < suits.length; i++) {
for (let x = 0; x < values.length; x++) {
let card = { Value: values[x], Suit: suits[i] };
deck.push(card);
}
}
// shuffle the cards
for (let i = deck.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * i);
let temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
console.log('The first five cards are:');
// display 5 results
for (let i = 0; i < 5; i++) {
console.log(`${deck[i].Value} of ${deck[i].Suit}`);
}