Project 2
This commit is contained in:
parent
e54eaabf63
commit
ec4ae6e57d
53
Chapter 11/Project 2
Normal file
53
Chapter 11/Project 2
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Star Rater</title>
|
||||
<style>
|
||||
.stars ul {
|
||||
list-style-type: none;
|
||||
padding: 0;
|
||||
}
|
||||
.star {
|
||||
font-size: 2em;
|
||||
color: #ddd;
|
||||
display: inline-block;
|
||||
}
|
||||
.orange {
|
||||
color: orange;
|
||||
}
|
||||
.output {
|
||||
background-color: #ddd;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<ul class="stars">
|
||||
<li class="star">✭</li>
|
||||
<li class="star">✭</li>
|
||||
<li class="star">✭</li>
|
||||
<li class="star">✭</li>
|
||||
<li class="star">✭</li>
|
||||
</ul>
|
||||
<div class="output"></div>
|
||||
<script>
|
||||
const starsUL = document.querySelector(".stars");
|
||||
const output = document.querySelector(".output");
|
||||
const stars = document.querySelectorAll(".star");
|
||||
stars.forEach((star, index) => {
|
||||
star.starValue = (index + 1);
|
||||
star.addEventListener("click", starRate);
|
||||
})
|
||||
function starRate(e) {
|
||||
output.innerHTML = `You Rated this ${e.target.starValue} stars`;
|
||||
stars.forEach((star, index) => {
|
||||
if (index < e.target.starValue) {
|
||||
star.classList.add("orange");
|
||||
} else {
|
||||
star.classList.remove("orange");
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user