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

Can you help me debug this?

I just want to mouseover a link on a page and get a prompt. The link's <a> tag has the id "takequiz". When I refresh the browser I get an error in the console that says "unexpected string" in line 4 (the line with the 'mouseover' event tag).

I'm sure whatever is wrong with this is obvious to everyone but me...?

const takequiz = document.getElementByID('takequiz');

takequiz.addEventListener('mouseover', () => {
  alert('Would you like to test your Memory Items knowledge?');
});

7 Answers

You have a small syntax error. You have capitalized the 'D' in 'Id. only the first letter of each new word is capitalized.

const takequiz = document.getElementById('takequiz');

You have ID capitalized. It's document.getElementById with a lowercase 'd'. I tested your code with this change and it works.

Thank you both. I made the correction but, oddly enough, am still getting the same error. Have tried it in a couple different browsers. Very puzzling!

Can you post your HTML page as well?

I can't right this moment but I'll be able to in a few hours. One thing I'm noticing is that when I click on the error in the console, it opens to the script for inspection and it's still showing code I wrote incorrectly several hours ago, not the actual current (and I think, correct) code. Why would it do that?

Here's the snippet of html with the mouseover link:

    <h3 style="text-align: center"><a id="takequiz" href="memoryquiz.html">MEMORY ITEMS</a></h3>

Ok guys I found the problem. Somehow an earlier version of the .js file had found its way into that folder...thanks for your help.