You are on page 1of 4

EXPERIMENT NO.

2
a. If…Else Statement – Write a program to accept average marks from student
and grades are computed and printed as follows:
Range Grade
<60 E
<70 D
<80 C
<90 B
<100 A

CODE:
<!--
Aniket Gholap
30
EXP 2 a.
-->
<!DOCTYPE html>
<html>
<head>
<title> If…Else Statement </title>
</head>
<body>
<script>
var marks= prompt(“Enter Your Total Academic Marks”);
document.write(“Your Total Academic Marks=\n”,marks,“<br/>”);
if (marks < 60) {
document.write(“Your Grade is E”);
}
else if (percentage < 70) {
document.write(“Your Grade is D”);
}
else if (percentage < 80) {
document.write(“Your Grade is C”);
}
else if (percentage < 90) {
document.write(“Your Grade is B”);
}
else {
document.write(“A grade”);
}
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------
OUTPUT:

----------------------------------------------------------------------------------------------------
b. Object & Getter – Setter.
1. Write a JavaScript code to create person object with properties firstname,
lastname, age, eyecolor, delete eyecolor property and display remaining
properties of person object.
CODE:
<!--
Aniket Gholap
30
EXP 2 b 1.
-->
<!DOCTYPE html>
<html>
<head>
<title> Object </title>
</head>
<body>
<script>
var person = {
firstname: “Aniket”,
lastname: “Gholap”,
age: 19;
eyecolor: “blue”
};
delete person.eyecolor;
document.write(“After delete” + “<br />” + person.firstname +
“<br />” + person.lastname + “<br />” + person.age + “<br />”
+ person.eyecolor);
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------
OUTPUT:
2. Write a JavaScript code to create object employee with property as ID and
demonstrate the use of setter and getter method.
CODE:
<!--
Aniket Gholap
30
EXP 2 b 2.
-->
<!DOCTYPE html>
<html>
<head>
<title> Getter & Setter </title>
</head>
<body>
<script>
var employee = {
ID: 27,
set identity(x) {
this.ID = x;
},
get details() {
return this.ID;
}
};
document.write(Employee.details + “<br />Employee ID”);

employee.identity = 38;
document.write(New Employee.details+”<br/>Employee ID);
</script>
</body>
</html>
----------------------------------------------------------------------------------------------------
OUTPUT:

You might also like