What is wrong with this basic Javascript code? [closed]

I found some issues with your code, just simple stuff that every beginner goes through (I did), I’ll bullet them off:

  • MyTitle isn’t myTitle, JavaScript variables are case-sensetive.
  • You should stay away from the onclick attribute; he’s a bad influence. The point, inline JS is generally not a good idea.
  • So I added an event listener event instead: [...].addEventListener("click", callback);
  • Your DOM request to the input box used an undefined variable/object/etc. called myTextBox, instead of a string "myTextBox".

Anyway, I made a JSFiddle for the code, so I could test it, so here is the link to the code with the edits I explained above: https://jsfiddle.net/Lktzw0Lh/

Leave a Comment