• Register
1 vote
73 views

Problem:

My code isn't running. In the console the error is “Uncaught SyntaxError: missing ) after argument list” but there are no missing ) I find.

Here is my code below:

var nav = document.getElementsByClassName('nav-coll');
for (var n = 0; n < button.length; n++) {
    nav[n].addEventListener('click',function(){
            console.log('haha');
        }
    }, false);
};

I’d be thankful to him if somebody pulls me up from here.

Thanks.

12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

We should always keep a sharp eye on our details in the code. Even a single semicolon (;) does matter here a lot.

As I can see all your logic, declaration and iteration are fine except parenthesis. You put an extra parenthesis in your code after the line

​console.log('haha');

I’ve removed the extra parenthesis from your code. Now it should run error-free. Give it a try now.

var nav = document.getElementsByClassName('nav-coll');
for (var n = 0; n < button.length; n++) {
    nav[n].addEventListener('click',function(){
            console.log('haha');
    }, false);
};

Thanks.

13 9 6
94,240 points

Related questions

0 votes
1 answer 17 views
17 views
I am having problem or facing the issue removing last character from string in JavaScript.
asked Sep 29, 2020 Daniel Anderson 4k points
0 votes
1 answer 17 views
17 views
I am finding the answers in several blog for removing particular character from string in java.
asked Sep 29, 2020 Daniel Anderson 4k points
0 votes
1 answer 28 views
28 views
I want to know a function built into Java that capitalizes the first character of each word in a String. It doesn&rsquo;t affect the others?
asked Sep 28, 2020 Daniel Anderson 4k points
0 votes
1 answer 11 views
11 views
I am finding difficulty with non repeated characters in a string in Java.
asked Sep 26, 2020 Daniel Anderson 4k points
0 votes
1 answer 31 views
31 views
I am finding the answers how to check string contains special characters in Java.
asked Sep 26, 2020 Daniel Anderson 4k points
0 votes
1 answer 25 views
25 views
I need someone to help me with C-style character string and if possible 1 example
asked Sep 25, 2020 okeke 360 points
0 votes
1 answer 10 views
10 views
I need to know how to remove the first cgaracter of a string in Java.
asked Sep 25, 2020 Daniel Anderson 4k points