Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 02a2150
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Dice Roller!</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const isFairDie = faces => { | ||
const validFaces = [2, 4, 6, 8, 10, 12, 20]; | ||
if (validFaces.includes(faces)) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
const tokyoDie = [ | ||
'Heart', | ||
'Attack', | ||
'Money', | ||
'One', | ||
'Two', | ||
'Three' | ||
] | ||
|
||
const roll = die => { | ||
if (Number.isInteger(die) && isFairDie(die)) { | ||
return Math.ceil(Math.random() * die); | ||
} else if (Array.isArray(die) && isFairDie(die.length)) { | ||
return die[Math.floor(Math.random() * die.length)]; | ||
} else { | ||
return 'Not a valid die'; | ||
} | ||
} | ||
|
||
console.log(roll(6)); | ||
console.log(roll(tokyoDie)); |