let value = getRandomIntInclusive(1, 6);
console.log(value)
let allDice = document.getElementsByClassName("dice")
let i = 0;
for (const elem of allDice) {
if (i == value - 1) {
elem.style.display = "flex"
} else {
elem.style.display = "none"
}
i++;
}
}
for (const elem of (document.getElementsByClassName("dice"))) {
elem.addEventListener("click", rollDice)
}
/*
DETAILED INSTRUCTIONS
1. pick out the neccesary elements from the HTML
2. Create other 5 dice faces in CSS
3. use eventlisteners on the appropriate div
4. Display dice faces randomly on click
STRETCH GOALS:
- Can you show the number you rolled as a integer along-side the dice face?
- Can you improve the overall design?
*/
/*
DESCRIPTION:
In this challenge a casino has asked you to make an online dice that works just like
it wold in real life. Using the pre-made dice face that represents ‘one’, make the
faces for ‘two’, ‘three’, ‘four’, ‘five’ and ‘six’. Now when the users clicks the
dice on the screen the dice is expected to show one of the faces randomly.
event listeners, Math.random()
*/
// Write your code here 👇
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min); //The maximum is inclusive and the
minimum is inclusive
}
function rollDice() {