Skip to content

Commit dd051ce

Browse files
committed
writing a different code for rolling the dice
1 parent 9178903 commit dd051ce

File tree

4 files changed

+68
-14
lines changed

4 files changed

+68
-14
lines changed

projects/dice-roll-simulator/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
const buttonEl = document.getElementById("roll-button");
23

34
const diceEl = document.getElementById("dice");
@@ -51,3 +52,44 @@ buttonEl.addEventListener("click", () => {
5152
rollDice();
5253
}, 1000);
5354
});
55+
56+
57+
58+
59+
// // Get references to DOM elements
60+
// let dice = document.querySelector('#dice');
61+
// let rollBtn = document.querySelector('#roll-button')
62+
// let rollHis = document.querySelector('#roll-history')
63+
64+
// //Function to generate random numbers between 1 and 6
65+
// function rollDice(){
66+
// let num = Math.floor(Math.random() * 6) + 1;
67+
// return num;
68+
// }
69+
// console.log(rollDice())
70+
// // // Add event listener to the button
71+
// rollBtn.addEventListener('click', function(){
72+
73+
// //Roll the dice
74+
// let rollResult = rollDice()
75+
76+
// //Update the dice display with rollResult
77+
// // string.fromCodePoint is the graphic representation of the dice face which convert the unicode
78+
// //unicode 9855 represent face 1
79+
// dice.textContent = String.fromCodePoint(9855 + rollResult);
80+
81+
// // Create a new list item to display the roll result
82+
// let newRollItem = document.createElement('li')
83+
// newRollItem.textContent = `Roll ${rollHis.childElementCount + 1}: ${dice.textContent}`
84+
85+
// // Add the roll item to the roll history
86+
// rollHis.appendChild(newRollItem)
87+
88+
// // Add roll animation class
89+
// dice.classList.add("roll-animation");
90+
// // Remove roll animation class after 1 second and roll the dice again
91+
// setTimeout(() => {
92+
// dice.classList.remove("roll-animation");
93+
// rollDice();
94+
// }, 1000);
95+
// })

projects/dice-roll-simulator/style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ h1 {
1111

1212
.dice {
1313
font-size: 7rem;
14-
margin: 5px;
14+
margin: 5px ;
1515
animation-duration: 1s;
1616
animation-fill-mode: forwards;
17+
color: red;
1718
}
1819

1920
.roll-animation {

projects/sticky-navbar/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="top-container">
2121
<h1>Welcome to our websiteh1>
2222
div>
23-
<div class="bottom-container">
23+
<div class="btm-container">
2424
<p class="text">
2525
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla tempore
2626
explicabo veritatis dignissimos accusantium nostrum voluptatum qui

projects/sticky-navbar/index.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
const navbarEl = document.querySelector(".navbar");
1+
// Select the element with the class "navbar" and store it in the variable navbarEl
2+
let navbarEl = document.querySelector('.navbar');
23

3-
const bottomContainerEl = document.querySelector(".bottom-container");
4+
// Select the element with the class "bottom-container" and store it in the variable bottomContainerEl
5+
let bottomContainerEl = document.querySelector('.btm-container')
46

7+
// Log the height of the navbar element to the console
58
console.log(navbarEl.offsetHeight);
69

10+
// Log the offset top position of the bottom container element to the console
711
console.log(bottomContainerEl.offsetTop);
812

9-
window.addEventListener("scroll", () => {
10-
if (
11-
window.scrollY >
12-
bottomContainerEl.offsetTop - navbarEl.offsetHeight - 50
13-
) {
14-
navbarEl.classList.add("active");
15-
} else {
16-
navbarEl.classList.remove("active");
17-
}
18-
});
13+
// Add a scroll event listener to the window
14+
window.addEventListener('scroll', () =>{
15+
16+
17+
// Check if the vertical scroll position is greater than the offset top position of the bottom container element
18+
// minus the height of the navbar element minus 50 pixels
19+
if(window.scrollY >
20+
bottomContainerEl.offsetTop - navbarEl.offsetHeight - 50 ){
21+
22+
// If the condition is true, add the class "active" to the navbar element
23+
navbarEl.classList.add('active')
24+
}
25+
// If the condition is false, remove the class "active" from the navbar element
26+
else{
27+
navbarEl.classList.remove('active')
28+
}
29+
})

0 commit comments

Comments
 (0)