I have 2 files, the first file name Web.htm
and the second file name Web.js
Web.htm:
<!DOCTYPE html>
<html>
<head>
<title>My website</title>
</head>
<body>
<script src="Web.js"></script>
</body>
</html>
Web.js
alert('Hello, World');
I already put the two files in the same folder but when I run the Web.htm, there isn’t have any box that show up and say Hello, World
But when remove the src in the <script> in the html file like this
<script>
alert('Hello, World');
</script>
It still working, so what happened with my JavaScript, did I need to host a website to make it work? I’m actually isn’t host it yet.
Sorry if this question is stupid, I’m actually a beginners of JavaScript.
Edit: I fix the scr to src but it still isn’t work.
Edit: I fix the problem, I installed and configure the HTTP server like esqew said in the comment and it work. Look like my computer isn’t installed the HTTP server yet, sorry you guy.
Seems like you have a typo.
try:
<script src="Web.js"></script>
When you are using a JavaScript file, you should NOT use HTML tags:
change your web.js file from:
<script>
alert('Hello, World');
</script>
to
alert('Hello, World');