ITM(SLS)BarodaUniversity
SchoolofComputerScience,EngineeringandTechnolog
y Diploma [Semester 3]
Subject:JavaScript
PRACTICAL - 1
Aim: Write a javaScript program to print hello world.Using
console.log() , alert() and document.write()
Code: <html>
<body>
<script>
document.write("Hello World!")
</script>
</body>
</html> [ For document.write ]
<html>
<body>
<script>
console.log('Hello World');
</script>
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
</body>
</html> [ For console.log ]
<html>
<body>
<script>
alert('Hello World');
</script>
</body>
</html> [For alert ]
Outputs : [ document.write ]
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
[ console.log ]
[ alert ]
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
PRACTICAL - 2
Aim: AIM : Create a const object called “item” to store
information shown in pic.
Keys = item-name ,rating , original-price , saleprice , offers
CODE :
const item = {
itemName: "JBL Earphones ",
ratings: "3.5",
sale: "30%",
originalPrice: "3000",
salePrice: "900",
offers: "5",
};
Output:
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
PRACTICAL - 3
Aim: Write a Java Script program to perform
Arithmetic Operation . Also give one line definition for
these operators(+,-,*,/,%) .
Code:
let a=10;
let b=20;
console.log("a+b=",a+b);
console.log("a-b=",a-b);
console.log("a*b=",a*b);
console.log("a/b=",a/b);
console.log("a%b=",a%b);
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
Output:
a+b= 30
a-b= -10
a*b= 200
a/b= 0.5
a%b= 10
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
PRACTICAL - 4 (a)
Aim: Define post and pre-increment.
Also define post and pre-decrement.
Write a JS program to perform Unary Operation.
->The increment operator (++) adds 1 from the operand.
If it is placed after the operand post-increment., it returns the
value before the increment.
If it is placed before the operand pre-increment, it returns the value
after the increment.
Code:
let a=10;
let b=10;
console.log("pre increment a=",++a);
console.log("post increment b=",b++);
Output: pre increment a= 11
post increment b= 10
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
PRACTICAL - 4 (b)
Aim: Write a JS program to perform Unary Operation.
The decrement operator (--) subtracts 1 to the operand.
If it is placed after the operand called post-decrement, it returns the value before
the decrement.
If it is placed before the operand pre-decrement, it returns the value after the
decrement.
Code:
let a=10;
let b=10;
console.log("pre decrement a=",--a);
console.log("post decrement b=",b--);
Output:
pre decrement a= 9
post decrement b= 10
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
PRACTICAL - 5
Aim: Write a JavaScript code which can give grades to
students according to their score (using else-if).
CODE :
let marks = prompt("Enter your marks");
if (marks >= 90 && marks < 101) {
console.log("You Score : A");
} else if (marks >= 75 && marks < 90) {
console.log("You Score : B");
} else if (marks >= 60 && marks < 75) {
console.log("You Score : C");
} else if (marks >= 40 && marks < 60) {
console.log("You Score : D");
} else if (marks >= 32 && marks < 40) {
console.log("You Score : E");
} else if (marks >= 0 && marks < 32) {
console.log("You Score : F");
} else {
Name: Rushikesh Tapre Enrollment No: 23C11138
ITM (SLS) Baroda University
School of Computer Science, Engineering and Technology
Diploma [Semester 3]
Subject: JavaScript
console.log("Enter correct marks");
Output:
Enter your marks : 80
You score: B
Name: Rushikesh Tapre Enrollment No: 23C11138