Skip to content

Commit

Permalink
Duplicate letters now pulse differently
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro270707 committed Oct 25, 2023
1 parent c404e28 commit 8abd315
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 4 additions & 0 deletions css/senha.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
border-color: #ff0000;
}

.character-slot.duplicate-letter {
border-color: #ff9900;
}

.character-slots {
display: flex;
gap: 0.25rem;
Expand Down
13 changes: 5 additions & 8 deletions js/senha.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,12 @@ document.addEventListener("keyup", (event) => {
}
if (hasDuplicateLetters(charactersInSlotArray)) {
let characterSlots = getCharacterSlots();
let seenLetters = '';
for (const slot of Array.from(characterSlots.children)) {
if (slot.innerHTML === ' ') {
continue;
}
if (seenLetters.includes(slot.innerHTML)) {
pulseSlotError(slot);
} else {
seenLetters += slot.innerHTML;
if (charactersInSlotArray.split(slot.innerHTML).length - 1 > 1) {
pulseSlotError(slot, "duplicate-letter");
}
}
}
Expand All @@ -224,12 +221,12 @@ document.addEventListener("keyup", (event) => {
}
});

function pulseSlotError(slot) {
function pulseSlotError(slot, errorClass = "error") {
slot.style.transition = "none";
slot.classList.add("error");
slot.classList.add(errorClass);
setTimeout(() => {
slot.style.transition = "border-color 1s";
slot.classList.remove("error");
slot.classList.remove(errorClass);
}, 20);
}

Expand Down

0 comments on commit 8abd315

Please sign in to comment.