Skip to content

Commit bde9930

Browse files
Add files via upload
0 parents  commit bde9930

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Emoji Rating</title>
8+
<link rel="stylesheet" href="style.css" />
9+
<link
10+
rel="stylesheet"
11+
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
12+
integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
13+
crossorigin="anonymous"
14+
referrerpolicy="no-referrer"
15+
/>
16+
</head>
17+
<body>
18+
<div class="feedback-container">
19+
<div class="emoji-container">
20+
<i class="fa-regular fa-face-angry fa-3x"></i>
21+
<i class="fa-regular fa-face-frown fa-3x"></i>
22+
<i class="fa-regular fa-face-meh fa-3x"></i>
23+
<i class="fa-regular fa-face-smile fa-3x"></i>
24+
<i class="fa-regular fa-face-laugh fa-3x"></i>
25+
</div>
26+
<div class="rating-container">
27+
<i class="fa-solid fa-star fa-2x"></i>
28+
<i class="fa-solid fa-star fa-2x"></i>
29+
<i class="fa-solid fa-star fa-2x"></i>
30+
<i class="fa-solid fa-star fa-2x"></i>
31+
<i class="fa-solid fa-star fa-2x"></i>
32+
</div>
33+
</div>
34+
<script src="index.js"></script>
35+
</body>
36+
</html>

index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const starsEl = document.querySelectorAll(".fa-star");
2+
const emojisEl = document.querySelectorAll(".fa-regular");
3+
const colorArray = ["red", "orange", "yellow", "blue", "green"];
4+
5+
updateRating(0);
6+
7+
starsEl.forEach((starEl, index) => {
8+
starEl.addEventListener("click", () => {
9+
updateRating(index);
10+
});
11+
});
12+
13+
// In a forEach loop, the function passed as an argument is called once for each element in the array. The function takes up to three arguments: the current element, the index of the current element, and the array being traversed.
14+
// The first argument, starEl, is the current element in the array, which represents a single star icon. The second argument, index, is the index of the current element in the array. So, in this loop, index represents the current index of the starEl element.
15+
16+
function updateRating(index) {
17+
starsEl.forEach((starEl, idx) => {
18+
if (idx < index + 1) {
19+
starEl.classList.add("active");
20+
} else {
21+
starEl.classList.remove("active");
22+
}
23+
});
24+
25+
emojisEl.forEach((emojiEl) => {
26+
emojiEl.style.transform = `translateX(-${index * 50}px)`;
27+
emojiEl.style.color = colorArray[index];
28+
});
29+
}

style.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
body {
2+
margin: 0;
3+
display: flex;
4+
justify-content: center;
5+
height: 100vh;
6+
align-items: center;
7+
background-color: #9eeb53;
8+
}
9+
10+
.feedback-container {
11+
background-color: #8bcff1;
12+
width: 400px;
13+
height: 200px;
14+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
15+
border-radius: 10px;
16+
position: relative;
17+
}
18+
19+
.emoji-container {
20+
position: absolute;
21+
left: 50%;
22+
transform: translateX(-50%);
23+
top: 20%;
24+
/* background-color: #ffa6ca; */
25+
width: 50px;
26+
height: 50px;
27+
border-radius: 50%;
28+
display: flex;
29+
overflow: hidden;
30+
/* will hide emojis outside of the container i.e. the other emojis */
31+
}
32+
33+
.fa-regular {
34+
margin: 1px;
35+
transform: translateX(0);
36+
transition: transform 0.2s;
37+
}
38+
39+
.fa-star{
40+
color: #43474b;
41+
cursor: pointer;
42+
}
43+
44+
.rating-container{
45+
position: absolute;
46+
left: 50%;
47+
transform: translateX(-50%);
48+
bottom: 20%;
49+
}
50+
51+
.fa-star.active{
52+
color: #fbc200;
53+
}

0 commit comments

Comments
 (0)