Use basic JavaScript methods like console.log(), alert(), and prompt()
:information_source: Info What is JavaScript?
JavaScript is a high-level programming language that makes web pages interactive. While HTML creates the structure and CSS adds style, JavaScript brings web pages to life with dynamic features!
Interactive Logic: JavaScript adds behavior and interactivity to web pages
Programming Language: It gives instructions to computers in a language they understand
Team Player: JavaScript works together with HTML and CSS to create amazing web experiences
On your browser, press F12 on your keyboard to view the console.
You can also right click on a webpage >>> select Inspect >>> choose the Console tab.
You can actually write any JavaScript here, but if you refresh the browser, the code that you have written in the Console will disappear!
This is because it is just to test code, you cannot save anything here.
Write your codes in an IDE (Integrated development environment) such as Visual Studio Code to save as script files locally on your computer or use glitch.com as an online IDE in your browser.
Then add the script to HTML by writing <script src="script.js"></script> inside the <body> section before the </body> closing tag so that the page content can be interactive.
html
<body><!-- ... all your HTML contents --><scriptsrc="script.js"></script></body>
But usually we don't write our scripts internally. We should keep our JavaScript code separate from our HTML code.
The internal way of <script> in <head> section will be used commonly to import JS libraries, or provide functions that have nothing to do with the HTML elements.