Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
acidtone committed Jul 23, 2022
0 parents commit 02a2150
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions index.html
@@ -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>
30 changes: 30 additions & 0 deletions js/dice-roller.js
@@ -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));

0 comments on commit 02a2150

Please sign in to comment.