Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

VES POLYTECHNIC CLIENT-SIDE SCRIPTING 22519

EXPERIMENT NO. 01

Title: - Develop JavaScript to use decision


making and looping statements.

D.O.P: -

D.O.S: -

MARKS: -

Marks Obtained Dated signature of


Teacher
Process Related Product Related Total (25)
(15) (10)

CO5I 2021-2022
Experiment No 01.
• Aim: Develop a JavaScript to use decision making and Looping
Statements.

• Practical Questions:
1. Write a program to display grade, Average, Percentage
obtained by Student.

CODE
<html>
<h4>program to display grade, average, percentage obtained
by student</h4>
<body>
<script type = "text/javaScript">
var sub1 = prompt("Enter Marks of AJP");
var sub2 = prompt("Enter Marks of CSS");
var sub3 = prompt("Enter Marks of OSY");
var sub4 = prompt("Enter Marks of CPP");
var sub5 = prompt("Enter Marks of EST");
if(sub1 <= 100 && sub2<=100 && sub3<=100 && sub4<=100 &&
sub5<=100){
var totalMarks =
parseInt(sub1)+parseInt(sub2)+parseInt(sub3)+parseInt(sub4)+parseInt(sub5);
var averageMarks = totalMarks/5;
var percentage = (totalMarks*100)/500
document.write("Student Name: Soham parab <br>");
document.write("Class: C05I(B) <br>");
document.write("Marks entered By the Student: <br>");
document.write("AJP: "+sub1+"/100 <br>");
document.write("CSS: "+sub2+"/100 <br>");
document.write("OSY: "+sub3+"/100 <br>");
document.write("CPP: "+sub4+"/100 <br>");
document.write("EST: "+sub5+"/100 <br>");
document.write("Total Marks = "+ totalMarks +"<br>");
document.write("Average Marks = "+ averageMarks +"<br>");
document.write("Percentage = "+ percentage +"% <br>");
if(percentage > 90){

CSS CO5I(B) 19
document.write("Grade: A");
}
else if(percentage > 70){
document.write("Grade: B");
}
else{
document.write("Grade: C");
}
}
else{
alert("Please Enter Correct marks");
}
</script>
<p>Designed By Soham Parab</p>
</body>
</html>

OUTPUT

CSS CO5I(B) 19
2. Fibonacci Series number.
CODE
<html>
<body>
<h3>Fibonaaci Series</h3>
<script type="text/javaScript">
var num1 = 0, num2 = 1,num3;
var limit = prompt("Enter Limit OF Fibonacci Series");
document.write(num1+"</br>");
document.write(num2+"</br>");
for(i=0;i<=limit;i++){
num3 = num1+num2;
document.write(num3+"</br>");
num1 = num2;
num2 = num3;
}
</script>
</body>
</html>

OUTPUT

CSS CO5I(B) 19
3. Factorial number
CODE
<html>
<head>
<h3>Factorial of a Number</h3>
<body>
<script type="text/javaScript">
var number = parseInt(prompt("Enter a positive integer: "));
if (number < 0) {
alert("Negative Number Entered")
}
else if (number == 0) {
document.write("The factorial of"+number+" is 1.");
}
else {
var fact = 1;
for (i = 1; i <= number; i++) {
fact *= i;
}
document.write("The factorial of "+number+ " is "+fact);
}
</script>
</body>
</head>
</html>
OUTPUT

CSS CO5I(B) 19
4.Display Even numbers Between 1 to 50
CODE
<html>
<h4>Even Numbers Between 1 to 50 are:</h4>
<body>
<script type="text/javaScript">
for(i=0;i<=50;i++){
if(i%2==0){
document.write(i+"</br>");
}
}
</script>
</body>
</html>
OUTPUT

CSS CO5I(B) 19
• Exercise
1. Explain any two features of JavaScript.
Ans: 1. Dynamic Typing:
JavaScript supports dynamic typing which means types of the variable are
defined based on the stored value. For example, if you declare a variable x then
you can store either a string or a Number type value or an array or an object.
This is known as dynamic typing.
2. Platform Independent:
This implies that JavaScript is platform-independent or we can say it is
portable; which simply means that you can simply write the script once and
run it anywhere and anytime. In general, you can write your JavaScript
applications and run them on any platform or any browser without affecting
the output of the Script.

2. What are the Conditional Operators in JavaScript?


Ans: The conditional (ternary) operator is the only JavaScript operator that takes
three operands: a condition followed by a question mark (?), then an expression to
execute if the condition is truthy followed by a colon (:), and finally the expression to
execute if the condition is false. This operator is frequently used as a shortcut for the
if statement.

3. Explain six types of values in JavaScript.


Ans: 1. Number: The Number data type is used to represent positive or negative
numbers with or without decimal place.
2. Boolean: The Boolean data type can hold only two values- True or False.
3. Undefined: The Undefined data type can only have one value- the special value
undefined. If a variable is declared, but has not been assigned a value, has the
value undefined.
4. Null: A null value means there is no value.
5. Object: An object is a key-value pair. The property Key is always a string, but the
value can be any data type.

CSS CO5I(B) 19
4. Explain the terms: Object, Method.
Ans:
Object:
objects in JavaScript may be defined as an unordered collection of related data, of
primitive or reference types, in the form of “key: value” pairs. These keys can be
variables or functions and are called properties and methods, respectively, in the
context of an object.
Method:
A JavaScript method is a property of an object that contains a function definition.
Methods are functions stored as object properties. Object method can be accessed
with the following syntax:

CSS CO5I(B) 19

You might also like