const tmp1 = document.querySelector('#first');
const clone1 = tmp1.content.cloneNode(true);
const tmp2 = document.querySelector('#second');
const clone2 = tmp2.content.cloneNode(true);
const tmp3 = document.querySelector('#third');
const clone3 = tmp3.content.cloneNode(true);
const tmp4 = document.querySelector('#fourth');
const clone4 = tmp4.content.cloneNode(true);
const tmp5 = document.querySelector('#fifth');
const clone5 = tmp5.content.cloneNode(true);
const tmp6 = document.querySelector('#sixth');
const clone6 = tmp6.content.cloneNode(true);
const clones = [clone1, clone2, clone3, clone4, clone5, clone6];
container.addEventListener('click', () => {
container.innerHTML = ''; // container.removeChild(dice);
let random = Math.floor(Math.random() * (5 - 0 + 1)) + 0;
container.appendChild(clones[random].cloneNode(true)); //appendChild without deleting the
referenced child
info.textContent = `You rolled: ${random + 1}`;
});
/*
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 👇
const dice = document.querySelector('.dice');
const container = document.querySelector('.container');
const info = document.querySelector('#info');