Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

jason limmm
jason limmm
7,791 Points

queryselect error

document.querySelector("button[type="button"]").addEventListener('click', req());

anything wrong with my queryselector, i can't seem to find the problem

<button type="button">no block i think</button>

here is the html

1 Answer

Steven Parker
Steven Parker
230,946 Points

It helps to know what course and lesson you are referring to, and to be able to see your code. You might want to take a look at this video about Posting a Question. And you may also want to view this one about sharing a snapshot of your workspace.

But putting a quoted term inside other quotes of the same kind causes the term to be taken as an identifier. You can see from the syntax coloring in the first line that the word button is not part of the quoted string. Use a different token (such as apostrophe) for the quotes inside the other quotes (or in this case you can omit them entirely).

Also, unless "req" is a function that returns another function, it probably should not have parentheses after it. As it is, what's being passed is the result of calling "req" instead of a reference to the function itself.

Steven Parker
Steven Parker
230,946 Points

My guess was right about those first 2 issues. Applying my suggestions would give you this:

document.querySelector("button[type='button']").addEventListener("click", req);
//                            note: ^      ^ different quotes                ^ no parentheses

But it also looks like the syntax inside the function is a bit off.   So instead of this:

      ()=>{setTimeout(document.getElementById("jsinsertion").innerHTML="ok ty", 8000)};

… you probably want this:

      setTimeout(() => {document.getElementById("jsinsertion").innerHTML = "ok ty";}, 8000);
//               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//               note: function definition INSIDE the setTimeout call, as first argument