Linking javascript to html


Replace this line with your code.


Hi @bradcandy,

Do you need help?


Yes I do. I am understanding the begining course subjects for html and css and also think I understand the java script code of making the text into bubbles and having them move and I want to take that javascript and put it into an html file I already have going. I want to know how to link the javascript to html. I also would like to know what code editor would be best for a newbie. I see the format of the courses of codecademy are in and I find that very simple to use but I can't figur out how to use different code editors the same way.


@bradcandy You can link JavaScript and HTML by adding a <script> tag just before </body> in the HTML file, with a src attribute pointing to the JS file. For example, if your JS file is named script.js and in the same directory as the HTML file, you would do this:

<script src="script.js"></script>

I also would like to know what code editor would be best for a newbie

Whichever one comes native on your system is what I'd recommend. Once you feel comfortable with that and decide you'd like to explore options, take a look at Visual Studio Code, Brackets, Atom, or Notepad++ [Windows only]


I a stuck on a code editor. I am using Brackets but live preview will not preview. I keep getting the attached error.


@bradcandy Have you tried renaming your HTML file to index.html, like the error says?


Yes. Still getting the same message. Even with the default index.html that came with brackets


@bradcandy In that case, I think the easiest thing for you to do would be to open the file directly in the browser (double-click on it from your file manager), and manually refresh each time you make a change.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.