Wednesday, April 23, 2025

JavaScript Multiple Parameters

Functions with multiple parameters are simply functions that take more than one input value. 


<!DOCTYPE html>
<html>
<head>
<!-- <script src="main.js"></script> -->
</head>
<body>

<script>

	function multi_param(x, y, z) {
		document.write(x);
		document.write("<br><br>");
		
		document.write(y);
		document.write("<br><br>");
		
		document.write(z);
		document.write("<br><br>");
	}
	
	multi_param(10, 50, 100);
	
</script>
	
</body>
</html>

This code defines a function named multi_param that takes three parameters: x, y, and z.

The function uses the document.write() method to write the values of each parameter to the web page, separated by two line breaks (<br><br>).

The code then calls the multi_param function once with the values 10, 50, and 100 as arguments.

When you run this code, you should see the values 10, 50, and 100 written to the web page, each separated by two line breaks. 


<!DOCTYPE html>
<html>
<head>
<!-- <script src="main.js"></script> -->
</head>
<body>

<script>

	function multiplication(x, y) {
		result = x * y;
		document.write("Result: " + result);
	}
	
	multiplication(100, 20);
	
</script>
	
</body>
</html>

This code defines a function named multiplication that takes two parameters: x and y.

The function multiplies the values of x and y together and stores the result in a variable named result.

It then uses the document.write() method to write a string to the web page that includes the word "Result" and the value of the result variable.

The code then calls the multiplication function once with the values 100 and 20 as arguments.

When you run this code, you should see the string "Result: 2000" written to the web page.

This code demonstrates how a function can perform some computation or action using its parameters and return a result to the caller.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...