Page 119 - CodePilot V5.0 C8
P. 119
Code Create a web page to demonstrate the use of basic mathematical operations
10 within functions.
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>Basic Mathematical Operations</TITLE>
</HEAD>
<BODY>
<SCRIPT>
// Function to add two numbers
function add(a, b) {
return a + b;}
// Function to subtract two numbers
function subtract(a, b) {
return a - b;}
// Function to multiply two numbers
function multiply(a, b) {
return a * b;}
// Function to divide two numbers
function divide(a, b) {
if (b === 0) {
return "Cannot divide by zero!";
}
return a / b;
}
let num1 = 15;
let num2 = 5;
document.write("Addition: " + add(num1, num2) + "<BR>");
document.write("Subtraction: " + subtract(num1, num2) + "<BR>");
document.write("Multiplication: " + multiply(num1, num2) + "<BR>");
document.write("Division: " + divide(num1, num2));
</SCRIPT>
</BODY>
</HTML>
TECH
T ¢ Cross-Site Scripting (XSS): A security vulnerability that allows attackers to inject malicious
E scripts into web pages viewed by other users.
R
M ¢ Debugging: The process of identifying and fixing errors or issues in a software program.
S
¢ Live Feed: A real-time stream of data, often used for updates as they happen.
117
JavaScript for Beginners

