Closed mdewey closed 6 years ago
I was trying to push to github and it gave me an error message. Not sure if it went through but looks like it's shuffling (much thanks to Michael and Jason for helping little details).
What is the link the repository?
title: All Cards on Deck!
In this project, you will use JavaScript to model a deck of playing cards. You'll also add functionality to it such as shuffling and dealing.
Shuffling Cards
Computers are notoriously bad at random numbers. This is a pretty deep and complex topic, but it's worth pointing out that most random numbers we use in computing are actually "pseudorandom". For this assignment, you will read about, then implement, a popular algorithm that shuffles the order of a finite set using JavaScript's built in
Math.random()
function as a pseudorandom number generator.Objectives
Requirements
You will model these in code, in any way you see fit. It may require you to experiment and try a number of techniques. There are many valid solutions. Your user interface should consist of a face down deck, and a face up "hand" of cards that have been dealt.
Read about, and implement the Fisher–Yates shuffle algorithm:
For our purposes,
n
is52
:Explorer Mode
Adventure Mode
Epic Mode
Additional Resources
A Hint on Random Numbers
This snippet will give you a random integer,
z
between0
andn
:Let's break this down from the inside out:
n
is20
.Math.random()
to generate a floating-point number between0
and1
. Let's assume our random value is0.42
.n
. If we think of this random value as a percentage, multiplying these gives us a number that is some "percentage" ofn
. Their product is8.4
, or 42% ofn
.Math.floor()
to round down to the nearest whole number, i.e.8
.Because we're rounding down, it's impossible to get
20
. This will give us an integer between0
and19
. This technique is perfect for finding a "random" index in an array of lengthn
.