GTU WTAD Practical 1 : Write a JavaScript that shows how a variables type can be changed on-the-fly.

GTU WTAD Practical 1 : Write a JavaScript that shows how a variables type can be changed on-the-fly.

WTAD Practical 1

This program demonstrate use of Javascript. Here I have change the datatype of the variable on the fly. When you want to re-utilize the the variable then you can use the same variable name and assign the value as you wish to store.

Jump to GTU WTAD Practical 2: JavaScript Demonstration.

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu01\

<html>
<head>
	<title> GTU WTAD Practical 1 : Write a JavaScript that shows how a variables type can be changed on-the-fly. </title>

	<script language="javascript">
		function gtu_prog1()
		{
			document.write("<br>Integer Value");
			n=100;
			document.write("<br> <b>Value of n is:"+n+ "</b>");
			
			document.write("<br><br>String Value<br>");
			n="Welcome to GTU WTAD Program 1"
			document.write("<b> Value of n is:"+n+"</b>");
			document.write("<br><br>Floating point Value<br>");
			n=1.2
			document.write("<b> Value of n is:"+n+"</b>");
		}
	</script>
</head>
<body>
	<center> <h2> GTU WTAD Practical 1 : Write a JavaScript that shows how a variables type can be changed on-the-fly. </h2></center>
	<script language="javascript">
		gtu_prog1()
	</script>
	
</body>
</html>

 

 Output

GTU WTAD Practical 1

 

What is JavaScript

JavaScript is popular Client Side scripting language basically used for many purpose including validation.

Hello World JavaScript using Document.Write() : This method is used to display some string on client browser.

<!DOCTYPE html>
<html>
<body>
    <script>
      document.write("Hello...");
    </script>
</body>
</html> 

 

Hello World JavaScript using alert() : This method is used to display message to user.

<!DOCTYPE html>
<html>
<body>
     <script>
          alert("Hello...");
     </script>
</body>
</html> 

 

Hello World JavaScript using getElementById() : This method is generally used to paste more data into Division Tag or Paragraph.

<!DOCTYPE html>
<html>
<body>
<div id="detail"> </div>
<script>
     document.getElementById("detail").innerHTML = "Adarsh Patel";
</script>
</body>
</html> 

 

How to Declare Variable in JavaScript
To declare Variable in Javascript var keyword is used. eg. var name=”Adarsh Patel”;

Is JavaSctipt Case Sensitive ?

Yes

 

Which operator is supported by JavaScript?

Almost all Operators which is available in C Like Language is supported by JavaScript.

 

How to Declare Button and Function in JavaScript ?

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
    document.getElementById("detail").innerHTML = "Wow it's Working fine !!!";
}
</script>
</head>
<body>
<input type="button" onClick="myFunction()" value="Click Here">
<div id="detail"> </div>
</body>
</html> 

 

Display Variable Value along with How to Contact Two String:

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
    <script>
        var myname = "Adarsh Patel";
        document.getElementById("demo").innerHTML = "My Name is : " + myname;
     </script>
</body>
</html>

.

Leave a Reply