Example : How to print/display messages in Java Script(JS) program?
<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write("Hello Inida");
                        //alert("Hello Inida");
                        //console.log("Hello India");
		</script>
	</body>
</html>

--------------------  OR  --------------------

<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write(" <h2> Hello Inida <h2> ");         
		</script>
	</body>
</html>

--------------------  OR  --------------------

<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
	<script>
	   document.write(" <div style='color:red;'> Hello Inida <div> ");
           document.write(" <div style='color:red;'> <h3>Hello Inida</h3> <div> ");          
	</script>
	</body>
</html>

--------------------  OR  --------------------
<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write("Hello Inida");
			document.write("Hello World");
		</script>
	</body>
</html>

Output: 
Hello InidaHello World

--------------------  OR  --------------------

<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write("Hello Inida");
			document.write(" ");
			document.write("Hello World");
		</script>
	</body>
</html>

Output: 
Hello Inida Hello World

--------------------  OR  --------------------

<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write("Hello Inida");
			document.write("</br>");
			document.write("Hello World");
		</script>
	</body>
</html>

Output: 
Hello Inida
Hello World

--------------------  OR  --------------------

<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			document.write("Hello Inida </br>");			
			document.write("Hello World");
		</script>
	</body>
</html>

Output: 
Hello Inida
Hello World
Example : A JS program to add two values and display them.
<html>
	<head>
		<h4>Message Printing</H4>
	</head>
	<body>
		<script>
			x=20;
			y=30;
			z=x+y;
			document.write(z);
			//alert(z);			
		</script>
	</body>
</html>

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
		<script>
			var x=20, y=30, z;
                        //let x=20, y=30, z;
			z=x+y;
			document.write(z);
			//alert(z);			
		</script>
	</body>
</html>

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
		<script>
			let x=20, y=35, z;
			z=x+y;
			document.write(z);
			//alert(z);			
		</script>
	</body>
</html>

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
	   <script>
		let x=20, y=35, z;
		z=x+y;
		document.write("The sum of " + x + " and " + y + " is = "+z);
		//alert(z);			
	   </script>
	</body>
</html>

Output :
The sum of 20 and 35 is = 55

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
	   <script>
		var x= parseInt(prompt("Enter first value"));
		var y= parseInt(prompt("Enter second value"));
		z=x+y;
		document.write("The sum of " + x + " and " + y + " is = "+z);
		//alert(z);			
	   </script>
	</body>
</html>

Output :
The sum of 20 and 35 is = 55

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
	   <script>
		var x= parseInt(prompt("Enter first value", "Enter Numeric value here"));
		var y= parseInt(prompt("Enter second value", "Enter Numeric value here" ));
		z=x+y;
		document.write("The sum of " + x + " and " + y + " is = "+z);
		//alert(z);			
	   </script>
	</body>
</html>

Output :
The sum of 20 and 35 is = 55

--------------------  OR  --------------------

<html>
	<head>
		<h4>Arithmetic Program</H4>
	</head>
	<body>
	   <script>
		var x= parseFloat(prompt("Enter first value", "Enter Float value here"));
		var y= parseFloat(prompt("Enter second value", "Enter Float value here" ));
		z=x+y;
		document.write("The sum of " + x + " and " + y + " is = "+z);
		//alert(z);			
	   </script>
	</body>
</html>

Output:
Arithmetic Program
The sum of 52.35 and 24.52 is = 76.87

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.