JavaScript supports mathematical operations such as addition, subtraction, multiplication, division, and more. These operations can be performed using the corresponding arithmetic operators: +
for addition, -
for subtraction, *
for multiplication, /
for division, %
for modulus (remainder), and **
for exponentiation.
<!DOCTYPE html>
<html>
<head>
<!-- <script src="main.js"></script> -->
</head>
<body>
<script>
function allofthem(x, y) {
document.write("Div: " + (x / y) + "<br>");
document.write("Mul: " + (x * y) + "<br>");
document.write("Sub: " + (x - y) + "<br>");
document.write("Add: " + (x + y) + "<br>");
//Remainder of division:
document.write("Mod: " + (x % y) + "<br>");
}
allofthem(10, 3);
</script>
</body>
</html>
This code defines a function called allofthem
which takes two arguments x
and y
. Within the function, there are several arithmetic operations being performed using these two arguments. Specifically, it performs division (x / y
), multiplication (x * y
), subtraction (x - y
), addition (x + y
), and finds the remainder of division (x % y
).
After defining the function, it is called with the arguments 10
and 3
, which will output the results of these arithmetic operations for those particular values. The results are printed to the web page using document.write()
, which writes the specified text (in this case, the results of the operations) to the page.
The modulo operation calculates the remainder of the division of two numbers. In JavaScript, the modulo operator is represented by the percent sign (%). For example, 10 % 3 would give the result of 1 because 10 divided by 3 is 3 with a remainder of 1. So, the modulo operation returns the remainder of 10 divided by 3.
No comments:
Post a Comment