Reputation: 21
Html file code I just tried the simple Hello World in javascript file
This is my atempt to show in the console a message using console.log. I used Atom and I opened it in Chrome , I press inspect , I go to console but there is no message.
Upvotes: 1
Views: 589
Reputation: 2705
If we create a html
and a javascript
file seperately, the javascript
file has to be specified in the html
as external javascript
file. Therefore <script src="index.js"></script>
has to be added to the html
in the above example.
A complete code example can be found below.
The content of index.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Hello World with JS</title>
</head>
<body>
<p>See the browser console for the console output.</p>
<script src="index.js"></script>
</body>
</html>
And the index.js
:
console.log("Hello World!")
As result we can see the "Hello World!"
log message in the browser console, when the html
page is loaded.
More details about using javascript
with the html
can be found here.
Upvotes: 1