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

Javascript code not working help?

When the user click the "Action' button, text should appear on the text field writing "Type your action here" but nothing is working, I wrote the same thing Jim Hoskins. But im not geting same result as him.

Link to hes video http://teamtreehouse.com/library/javascript-foundations/functions/examples

Link to my code

http://jsfiddle.net/qgkkpmy4/

Btw don't mind the CSS, I have a thing for the color GOLD.

Hello Edgar Gil,

Looks like you simply mistyped your document.getElementById as document.GetElementById. Javascript is not forgiving for these issues, and can drive you crazy. I would advise checking the console for errors when things are not working.

I've corrected it below.

var button = document.getElementById('action');
var input = document.getElementById('text_field');


button.addEventListener ('click', function () {
  console.log('Clicked');
});

button.addEventListener ('click', function () {
  console.log('Other Clicking');
  input.setAttribute('value', 'Type Your Action Here');

});

Best, Travis Thompson

2 Answers

Edgar,

You have a capitalization error. You have 'document.GetElementById()', you need 'document.getElementById()' (i.e. do not capitalize the G).

Erik

Wow, can't believe this. I need to upgrade my problem solving skills. Thank you

These are the most common and most difficult to spot types of errors; it's not just you by a long shot! Even veteran programmers will run into these problems and can get stuck trying to debug them for hours. Spelling mistakes, missing punctuation, capitalization errors, etc. are all very tricky to hunt down, especially when you're so close to the code. That's where an extra set of eyes can help :)

Happy coding!

Erik

Thank Erik! But what really got me confuse was the "JSHint" in http://jsfiddle.net/qgkkpmy4/ . Because when i click on the JSHint I get :

JSHint Valid! Close window Good work! Your JavaScript code is perfectly valid.

So i got me really confuse as to why is not working when the Hint is telling me everything was fine. But i keep my eye open for next time. Thank you!