From 9268c246d1d24de6d3801328e5b9b2a053d5c041 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 12 Dec 2022 21:59:59 -0500 Subject: [PATCH] inporve rollDice and added dynamic menu items - js --- menu/menu.js | 37 ++++++++++++++++++++++++++++++++++++- menu/test.html | 36 ++++++++++++++++++++++++++++++++++++ rollDice/dice.css | 22 +++++++++++++++------- rollDice/dice.js | 19 ++++++++++++++----- rollDice/index.html | 28 +++++++++++++++++++--------- 5 files changed, 120 insertions(+), 22 deletions(-) create mode 100644 menu/test.html diff --git a/menu/menu.js b/menu/menu.js index ba9a5bf..146e232 100644 --- a/menu/menu.js +++ b/menu/menu.js @@ -1,4 +1,39 @@ -var navString = '' +// var navString = '' +let navString = ''; +let baseLinks = [ + ' Home ', + ' Resume ' +]; +let gameLinks = [ + ' Yatzee ', + ' Tic Tac Toe ', + ' Bingo ', + ' Memory ', + ' MTG Life Counter ' +]; +let utilLinks = [ + ' Speak ', + ' Binary to ASCII ', + ' YouTube Converter ', + ' NATO Alpha ', + ' Roll Dice ' + +]; + +navString = '' + document.getElementById('navContainer').innerHTML = navString; document.addEventListener('DOMContentLoaded', () => { diff --git a/menu/test.html b/menu/test.html new file mode 100644 index 0000000..c1d4036 --- /dev/null +++ b/menu/test.html @@ -0,0 +1,36 @@ + \ No newline at end of file diff --git a/rollDice/dice.css b/rollDice/dice.css index ed515c0..5130946 100644 --- a/rollDice/dice.css +++ b/rollDice/dice.css @@ -28,18 +28,21 @@ body{ padding: 2rem; } -#numberOfDiceSelection{ - padding-top: 5%; - padding-right: 5%; - width:100%; +.numberOfDiceSelection{ + /* padding-top: 5%; */ + /* padding-right: 2%; */ + /* width:100%; */ + /* margin: auto; */ + margin-top: 2%; display: flex; - justify-content: center; - font-size: 24px; + flex-direction: row; + justify-content: space-evenly; + font-size: 2rem; color: #fffb96; } input[type=radio] { border: 0px; - width: 100%; + /* width: 90%; */ height: 2em; } .die{ @@ -53,6 +56,11 @@ height:7.75em; color: white;; } +#inputSum{ + text-align: center; + margin: auto; +} + .wrapper{ position:fixed; right:0; diff --git a/rollDice/dice.js b/rollDice/dice.js index 5abe3ba..ab8f4c4 100644 --- a/rollDice/dice.js +++ b/rollDice/dice.js @@ -1,6 +1,6 @@ -let numberOfDice = 2; +let numberOfDice = 6; let die_value = []; - +let sum = 0; function newDiceNumber() { die_value = []; for (i = 1; i < 7; i++) document.getElementById("die" + i).innerHTML = ""; @@ -17,24 +17,25 @@ function newDiceNumber() { function shuffle_dice() { document.getElementById("math").style.display = "block" let addition = ""; - let sum = 0; + sum = 0; for (i = 0, j = 1; i < die_value.length; i++, j++) { var rand = Math.floor(Math.random() * 6) + 1; die_value[i][0] = "" die_value[i][1] = rand; document.getElementById("die" + j).innerHTML = die_value[i][0]; addition += ` ${die_value[i][1]}` + " "; - sum = sum + die_value[i][1]; + sum += + die_value[i][1]; if (i < die_value.length -1) {addition += "+"; } else addition += "= "; } document.getElementById("numbers").innerHTML = addition + sum; + return sum; } function showMath(){ - var numBlock = document.getElementById('numbers'); + console.log(numBlock.style.display) if (numBlock.style.display === "none") {     numBlock.style.display = "block";   } else { @@ -43,6 +44,14 @@ function showMath(){ } +function inputCorrect(){ + answer = document.getElementById('answer').value; + if (answer == sum) {alert('Nice job!'); shuffle_dice();} + else if (answer > sum) alert('Sorry, try again, too high...'); + else if (answer < sum) alert('Sorry, try again, too low...'); + document.getElementById('answer').value = ''; +} + function die_gif() { for (i = 0, j = 1; i < die_value.length; j++, i++) { die_value[i][0] = ""; diff --git a/rollDice/index.html b/rollDice/index.html index f06c602..4fb44df 100644 --- a/rollDice/index.html +++ b/rollDice/index.html @@ -33,17 +33,27 @@ -
- 1 - 2 - 3 - 4 - 5 - 6 +
+ 1 + 2 + 3
+
+ 4 + 5 + 6 +
+

-
+ +
+ How much to the dice add up to?:
+
+ +
+ +
-