- Create the following folder/file structure:
/ex_4 |-- index.html |-- scripts.js
- Add the following files to the folder:
index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Hello World</title> <script src="./scripts.js"></script> </head> <body> <h1 id="heading"></h1> </body> </html>
scripts.jswindow.onload = () => { let page = { title: "Hello world" }; let heading = document.querySelector("h1"); heading.innerText = page.heading; };
- Run the application using
http-serveror just open theindex.html
- Once we start the project it will output the following message on the page Hello world