-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solucionado o desafio unico da aula 015
- Loading branch information
1 parent
ab3d495
commit d6a5a50
Showing
7 changed files
with
105 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Desafio Único Collabcode aula 015 | ||
|
||
- Descrição: | ||
- Utilizando um evento de clique faça o preenchimento das estrelas. Se estiver preenchida, ao clicar deve sumir o preenchimento, e caso esteja vazia, ao clicar, seja preenchida com a cor. | ||
- Observação para este desafio: | ||
Caso clique na terceira estrela, a segunda e a primeira tambem devem ser preenchidas, e caso clique na primeira as seguintes devem desativar o preenchimento. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,64 @@ | ||
document.addEventListener('DOMContentLoaded', function(){ | ||
addListeners(); | ||
setRating(); | ||
}); | ||
|
||
function addListeners(){ | ||
var stars = document.querySelectorAll('.star'); | ||
[].forEach.call(stars, function(star, index){ | ||
star.addEventListener('click', (function(idx){ | ||
console.log('adding rating on', index); | ||
document.querySelector('.stars').setAttribute('data-rating', idx + 1); | ||
console.log('Rating is now', idx+1); | ||
setRating(); | ||
}).bind(window,index) ); | ||
const $stars = document.querySelectorAll(".star"); | ||
const $starsRemove = document.querySelectorAll(".star"); | ||
const lastIndex = $stars.length-1; | ||
|
||
$stars[0].addEventListener("click", lastStar); | ||
$stars[1].addEventListener("click", fourthStar); | ||
$stars[2].addEventListener("click", thirdStar) | ||
$stars[3].addEventListener("click", secondStar); | ||
$stars[lastIndex].addEventListener("click", firstStar); | ||
|
||
function lastStar() { | ||
$stars.forEach(function($star, key){ | ||
console.log($star, key); | ||
$star.classList.add("-active"); | ||
}); | ||
} | ||
|
||
function fourthStar() { | ||
$stars.forEach(function($star, key){ | ||
console.log($star, key); | ||
if(key>0){ | ||
$star.classList.add("-active"); | ||
} | ||
$starsRemove[0].classList.remove("-active"); | ||
}); | ||
|
||
} | ||
|
||
function setRating(){ | ||
var stars = document.querySelectorAll('.star'); | ||
var rating = parseInt( document.querySelector('.stars').getAttribute('data-rating') ); | ||
[].forEach.call(stars, function(star, index){ | ||
if(rating > index){ | ||
star.classList.add('rated'); | ||
console.log('added rated on', index ); | ||
}else{ | ||
star.classList.remove('rated'); | ||
console.log('removed rated on', index ); | ||
function thirdStar() { | ||
$stars.forEach(function($star, key){ | ||
console.log($star, key); | ||
if(key>1){ | ||
$star.classList.add("-active"); | ||
} | ||
$starsRemove[1].classList.remove("-active"); | ||
$starsRemove[0].classList.remove("-active"); | ||
}); | ||
} | ||
|
||
|
||
|
||
function secondStar() { | ||
$stars.forEach(function($star, key){ | ||
console.log($star, key); | ||
if(key>2){ | ||
$star.classList.add("-active"); | ||
} | ||
$starsRemove[2].classList.remove("-active"); | ||
$starsRemove[1].classList.remove("-active"); | ||
$starsRemove[0].classList.remove("-active"); | ||
}); | ||
} | ||
|
||
function firstStar() { | ||
$stars.forEach(function($star, key){ | ||
console.log($star, key); | ||
if(key>3){ | ||
$star.classList.add("-active"); | ||
} | ||
$starsRemove[3].classList.remove("-active"); | ||
$starsRemove[2].classList.remove("-active"); | ||
$starsRemove[1].classList.remove("-active"); | ||
$starsRemove[0].classList.remove("-active"); | ||
}); | ||
} | ||
|
||
|