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

how do i link the jquery file to the html properly?

Uncaught ReferenceError: $ is not defined at app.js:36

i tried to import and watch a few youtube videos but i dont think im doing it right.

please see snapshot for your reference: https://w.trhou.se/4uwdez1wfi iu any hints, suggestions and comments are very much appreciated thank you so much in advance for your help.

1 Answer

Martin Balon
Martin Balon
43,651 Points

Hi Karl,

I've checked both your app.js and index.html. All you have to do is to move jQuery above your app.js in index.html.

  <!-- jQuery first -->
  <script
  src="https://code.jquery.com/jquery-3.6.0.js"
  integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
  crossorigin="anonymous"></script>

  <!-- then app.js -->
  <script src="app.js"></script>

</body>
</html>

Now this will get rid of $ issue but there are other problems.

1) You are using js function submit() to submit the form but using document.getElementById("myForm").submit(); (Last line in app.js). The problem is that there is no form with id "myForm" so you will get an error. Also even though you will give your form this id your code will submit the form without any validation. You can use onsubmit to trigger an event when a form is submitted and then submit the form only if all fields are valid. For more details click on the link below:

https://www.w3schools.com/jsref/event_onsubmit.asp

2) You are using validateData function to validate users input using regex - that's fine but there is a function "validateName" - line 114 in app.js which is not defined. I guess you wanted to use validateData too and use regex to validate name?

Fix these two problems and see if the code gives you any other errors.