First, create a folder for your website project.
In this example:
index.html = your webpagescript.js = your JavaScript filestyle.css = your stylesCreate a file named:
script.js
Add some JavaScript code inside it:
alert("Hello from JavaScript!");
Open your index.html file and add the
<script> tag before the closing
</body> tag.
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Hello World</h1>
<script src="script.js"></script>
</body>
</html>
Double-click index.html.
Your browser will:
HTML:
<button onclick="sayHello()">
Click Me
</button>
JavaScript (script.js):
function sayHello() {
alert("Hello!");
}
.js file<script src="script.js"></script>