+ 1

Javascript Error

let count = 0; // select value and buttons const value = document.querySelector("#value"); const btns = document.querySelectorAll(".btn"); btns.forEach(function (btn) { btn.addEventListener("click", function (e) { const styles = e.currentTarget.classList; if (styles.contains("decrease")) { count--; value.textContent = count; }); }); Error: SyntaxError: Unexpected token ')' at /script.js:12:4 Why is an error coming? How to fix it?

30th Aug 2020, 1:25 PM
Kunsh-Tyagi
Kunsh-Tyagi - avatar
6 ответов
+ 5
I agree with RKK, codes being posted in raw text format is hard to debug. I had to copy it, paste it in an empty code and add a few dummy HTML elements just so that the querySelector* call doesn't complain about things not being there. And after some trials and errors (LOL) I managed to get the code to run. But the bad thing is, now that the code runs, I can't even remember which parts did I change (sigh). Well anyways ... btns.forEach(function (btn) { btn.addEventListener("click", function (e) { const styles = e.currentTarget.classList; if (styles.contains("decrease")) { count--; value.textContent = count; } }); });
30th Aug 2020, 1:51 PM
Ipang
+ 5
you've one unnecessary extra ")" somewhere. it's hard to debug this way please share the link to the code here so that it will be easy to debug together.
30th Aug 2020, 1:35 PM
minirkk
minirkk - avatar
+ 5
Ipang you added a paren to close the if statement.👍😉
30th Aug 2020, 1:57 PM
ODLNT
ODLNT - avatar
+ 4
Ooh Big Thanks ODLNT 🙏 I swear I really forgot what change actually got the warning off ...
30th Aug 2020, 1:59 PM
Ipang
+ 4
Really sorry everyone. Will do it from afterwards @RKK and @lpang. Apologies for the Inconvenience. BTW thanks @lpang and @ODLNT
30th Aug 2020, 2:03 PM
Kunsh-Tyagi
Kunsh-Tyagi - avatar
+ 3
A big thanks to everyone who supported me.
30th Aug 2020, 2:04 PM
Kunsh-Tyagi
Kunsh-Tyagi - avatar