+ 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?
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;
}
});
});
+ 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.
+ 5
Ipang you added a paren to close the if statement.👍😉
+ 4
Ooh Big Thanks ODLNT 🙏
I swear I really forgot what change actually got the warning off ...
+ 4
Really sorry everyone. Will do it from afterwards @RKK and @lpang. Apologies for the Inconvenience. BTW thanks @lpang and @ODLNT
+ 3
A big thanks to everyone who supported me.