JS Practical 1-1 (1)
JS Practical 1-1 (1)
-------------------------------------------------------------------------------------------------------------------------------
Title: - Write a JavaScript program to calculate the area of triangle, area of rectangle and area
of circle
Objective: - To learn the syntax, data types, variables in and to learn how functions are used in
Java script.
Hardware/Software: -
1. Personal computer with windows XP/vista or any higher version.
Theory: -
a) JavaScript variable: It is simply a name of storage location. There are two types of
variables in JavaScript: local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
1. Name must start with a letter (a to z or A to Z), underscore (_), or dollar ($) sign.
2. After first letter we can use digits (0 to 9), for example value1.
3. JavaScript variables are case sensitive, for example x and X are different variables.
b) JavaScript functions: They are used to perform operations. We can call JavaScript
function many times to reuse the code. It can have 0 or more arguments.
JAVASCRIPT CODE
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8">
<title>
JavaScript function to find
the area of a triangle and circle
</title>
</head>
<h4>
JavaScript function to find
the area of a circle, triangle and rectangle
</h4>
<label for="radius">
Enter the value radius:
</label>
<label for="side1">
Enter the value of side 1:
</label>
<label for="side2">
Enter the value of side 2:
</label>
<label for="side3">
Enter the value of side 3:
</label>
<label for="length">
Enter the value length:
</label>
<label for="breadth">
Enter the value breadth:
</label>
<script type="text/javascript">
function Area_circle(){
var r = document.getElementById('radius').value;
alert("The area of the circle is " + (r * r * Math.PI));
}
function Area_triangle() {
var side1 = parseInt(document
.getElementById("side1").value);
console.log(typeof(side1));
var s = (side1 + side2 + side3) / 2;
document.getElementById(
"display").innerHTML = area;
}
function Area_rectangle(){
var length = parseInt(document
.getElementById("length").value);
}
</script>
</body>
</html>
OUTPUT:
CONCLUSION: