0% found this document useful (0 votes)
6 views6 pages

JS Practical 1-1

The document outlines a JavaScript program designed to calculate the areas of a triangle, rectangle, and circle. It covers JavaScript syntax, variable types, and the use of functions for code reusability. The provided code includes HTML and JavaScript to create a user interface for input and display of calculated areas.

Uploaded by

meghshamjade50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

JS Practical 1-1

The document outlines a JavaScript program designed to calculate the areas of a triangle, rectangle, and circle. It covers JavaScript syntax, variable types, and the use of functions for code reusability. The provided code includes HTML and JavaScript to create a user interface for input and display of calculated areas.

Uploaded by

meghshamjade50
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

BE-ENTC SUB- JavaScript

-------------------------------------------------------------------------------------------------------------------------------

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.

2. VS code or any Text Editor

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.

Advantage of JavaScript function

There are mainly two advantages of JavaScript functions.

1. Code reusability: We can call a function several times so it saves coding.


2. Less coding: It makes our program compact. We don’t need to write many lines of
code each time to perform a common task.

The syntax of declaring function is given below.

function functionName([arg1, arg2, ...argN]){


//code to be executed
}

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>

<body style="text-align: center;">


<h1 style="color: rgb(128, 26, 0);">
JSPM's BSIOTR <br> JavaScript Practical 1
</h1>

<h4>
JavaScript function to find
the area of a circle, triangle and rectangle
</h4>

<label for="radius">
Enter the value radius:
</label>

<input type="number" id="radius"


placeholder="Enter the radius">
<br><br>

<label for="side1">
Enter the value of side 1:
</label>

<input type="number" id="side1"


placeholder="Enter value of side 1">
<br><br>

<label for="side2">
Enter the value of side 2:
</label>

<input type="number" id="side2"


placeholder="Enter value of side 2">
<br><br>

<label for="side3">
Enter the value of side 3:
</label>

<input type="number" id="side3"


placeholder="Enter value of side 2">
<br><br>

<label for="length">
Enter the value length:
</label>

<input type="number" id="length"


placeholder="Enter the length">
<br><br>

<label for="breadth">
Enter the value breadth:
</label>

<input type="number" id="breadth"


placeholder="Enter the breadth">
<br><br>

<button onclick="Area_circle()">Click Here for area of circle!</button>


<button onclick="Area_triangle()">Click Here for area of triangle!</button>
<button onclick="Area_rectangle()">Click Here for area of rectangle!</button>
<p>
Area of Triangle: <span id="display"></span>
</p>

<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);

var side2 = parseInt(document


.getElementById("side2").value);

var side3 = parseInt(document


.getElementById("side3").value);

console.log(typeof(side1));
var s = (side1 + side2 + side3) / 2;

var area = Math.sqrt(s * ((s - side1)


* (s - side2) * (s - side3)));

document.getElementById(
"display").innerHTML = area;
}

function Area_rectangle(){
var length = parseInt(document
.getElementById("length").value);

var breadth = parseInt(document


.getElementById("breadth").value);

alert("Area of rectangle: "+(length*breadth)) ;

}
</script>
</body>

</html>
OUTPUT:
CONCLUSION:

You might also like