Where to run JavaScript

<!DOCTYPE html>
<!-- color -->
<html>
  <head>
    <title>My first JavaScript</title>
  </head>
  <body>
    <h1>My first JavaScript</h1>
    <p>Click the button to display the date and time.</p>
    <button onclick="document.getElementById('demo').innerHTML = Date()">
      The time is?
    </button>
    <p id="demo"></p>
  </body>
</html>
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license

JavaScript

https://github.com/web-classroom/heig-vd-web-course

Markdown ยท PDF

This work is licensed under the CC BY-SA 4.0 license.

HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license

External file

<!DOCTYPE html>
<html>
  <head>
    <title>My first JavaScript</title>
    <script src="myScript.js"></script>
  </head>
  <body>
    <h1>My first JavaScript</h1>
    <p>Click the button to display the date and time.</p>
    <button onclick="displayDate()">The time is?</button>
    <p id="demo"></p>
  </body>
</html>
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license
function displayDate() {
  document.getElementById("demo").innerHTML = Date();
}
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license

Console

console.log("Hello, World!");
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license

Node.js

console.log("Hello, World!");
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license
node myScript.js
HEIG-VD - WEB Course 2023-2024 - AGPL-3.0 license