From c7f0f52fbf023611ff893b938193a6ff04ad4bc9 Mon Sep 17 00:00:00 2001 From: Cihat Uysal <30296073+SupermanStandingOnKryptonite@users.noreply.github.com> Date: Tue, 15 Dec 2020 23:53:58 +0300 Subject: [PATCH] fixed a bug accurs when clicking first cup Bug accurs if you have more than one cup filled and try to click first cup. --- drink-water/script.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drink-water/script.js b/drink-water/script.js index c96d09d..89ccc50 100644 --- a/drink-water/script.js +++ b/drink-water/script.js @@ -11,8 +11,14 @@ smallCups.forEach((cup, idx) => { function highlightCups(idx) { if (idx===7 && smallCups[idx].classList.contains("full")) idx--; - if(smallCups[idx].classList.contains('full') && !smallCups[idx].nextElementSibling.classList.contains('full')) { - idx-- + if (smallCups[idx] === smallCups[0]) { + cup.classList.remove("full"); + smallCups[idx].classList.add("full"); + } else if ( + smallCups[idx].classList.contains("full") && + !smallCups[idx].nextElementSibling.classList.contains("full") + ) { + idx--; } smallCups.forEach((cup, idx2) => { @@ -46,4 +52,4 @@ function updateBigCup() { remained.style.visibility = 'visible' listers.innerText = `${2 - (250 * fullCups / 1000)}L` } -} \ No newline at end of file +}