Example: Simple Output and Math in JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript Example</title>
</head>
<body>
<script>
document.write("<p>Sample JavaScript Program</p>");
document.write("<p>" + 2 * 4 + "</p>");
</script>
</body>
</html>
Output:
Sample JavaScript Program
8
In the next Javascript examples, we will simply show the code within the HTML body tags (and not the HTML DocType, etc.).
Example: Simple Output and Math in JavaScript
<body>
<button type="button" onclick="document.write(2 * 3)">Compute</button>
</body>
Example: Alert (Popup) Box in JavaScript
<body>
<button onclick="alert('Welcome to my JavaScript Program');">Click Me</button>
</body>