Js1 (6 Files Merged) 2
Js1 (6 Files Merged) 2
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 ]
[ console.log ]
[ alert ]
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:
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);
Output:
a+b= 30
a-b= -10
a*b= 200
a/b= 0.5
a%b= 10
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.
Code:
let a=10;
let b=10;
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
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");
} else {
Output:
Enter your marks : 80
You score: B