Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 83 - 2609_Logicode
P. 83

    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>

                            Hashtag

                          #Cross-Site Scripting (XSS): A security vulnerability that allows attackers to inject malicious
                          scripts into web pages viewed by other users.
                          #Debugging: The process of identifying and fixing errors or issues in a software program.
                          #Live Feed: A real-time stream of data, often used for updates as they happen.

                                                                                               JavaScript for Beginners  81

| 78 79 80 81 82 83 84 85 86 87 88 |