HTML AND JAVASCRIPT
HTML AND JAVASCRIPT
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Tag Description
<html> Root element of an HTML page
Contains meta information and links
<head>
to styles/scripts
Sets the title of the web page
<title>
(shown in the browser tab)
Contains the visible content of the
<body>
web page
Headings (h1 is the largest, h6 is the
<h1> to <h6>
smallest)
<p> Paragraph of text
<a href="URL"> Creates a hyperlink
<img src="image.jpg"> Displays an image
<ul> & <ol> Unordered and ordered lists
<li> List item
<table> Creates a table
<tr>, <td> Table row and table cell
<form> Creates an input form
Input field (text, password, submit,
<input>
etc.)
<label for="name">Name:</label>
<label for="email">Email:</label>
</form>
INTRODUCTION TO JAVASCRIPT
<script>
alert("Welcome to my website!");
</script>
<script src="script.js"></script>
// script.js file
VARIABLES IN JAVASCRIPT
Variables store data values. JavaScript has three ways to declare variables:
Type Example
String "Hello, World!"
Number 100, 3.14
Boolean true, false
Array ["Apple", "Banana", "Orange"]
Object {name: "John", age: 25}
Operators in JavaScript
Conditional Statements
} else {
Loops in JavaScript
For Loop
While Loop
let i = 0;
while (i < 5) {
i++;
Selecting Elements
document.querySelector(".myClass").style.color = "blue";
Handling Events
Events allow user interactions.
<script>
function sayHello() {
alert("Hello, user!");
</script>
JavaScript Functions
Defining a Function
function greet(name) {
console.log(greet("Alice"));
</form>
<script>
function validateForm() {
return false;
return true;
</script>
localStorage.setItem("username", "Alice");
alert(localStorage.getItem("username"));
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="display()">Submit</button>
<p id="output"></p>
<script>
function display() {
</script>
</body>
</html>