Javascript not working when put in external file


#1

when i create an external file of a javascript file and try to run it, it displays text from external file and does not display web page , what am i doing wrong?


#2

It’s impossible for us to tell you based on that description. If you show the files and what the end result looks like, we might have more insight.


#3

i hope the picture is clear


#4

I want it to show the Alert box displaying “hey, this works, too!”


#5

i hope the picture is clear, I want the external file to show the Alert box displaying “hey, this works, too!”


#6

From what I can tell, you’re just right clicking on the file and selecting “open in browser”.

If so, that’s not how you run JS files. Only HTML files work like that.


#7

Ok it makes sense, now how do you run a JS file?


#8

Normally, through an HTML file like the one you already have. You can use the src attribute to link an external JS file

https://www.w3schools.com/tags/att_script_src.asp