CSS - Practical 1
CSS - Practical 1
Q2. Write a program to take the user’s name as input and print it.
Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
let name=prompt("Enter The Name")
document.write("Your name is "+name)
</script>
</head>
<body>
</body>
</html>
Output:-
Q3. Write a program for arithmetic expression evaluation and message printing.
Code:-
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
let num1=Number.parseFloat(prompt("Enter the number 1"))
let num2=Number.parseFloat(prompt("Enter the number 2"))
alert("Addition of "+num1+" and "+num2+" = "+(num1+num2))
alert("Subtraction of "+num1+" and "+num2+" = "+(num1-num2))
alert("Multiplication of "+num1+" and "+num2+" = "+(num1*num2))
alert("Division of "+num1+" and "+num2+" = "+(num1/num2))
</script>
</head>
<body>
</body>
</html>
Output:-
Q4. Program to demonstrate getter and setter.
Code: -
<html>
<head>
<title>Anas Qureshi-220440</title>
<script>
document.write("Anas Qureshi-220440 <br><hr>")
const person = {
firstName: "Anas",
lastName: "Qureshi",
get fullName() {
return `${this.firstName} ${this.lastName}`
},
set fullName(name) {
const parts = name.split(" ")
this.firstName = parts[0]
this.lastName = parts[1]
},
};
document.write("First Name:- "+person.firstName + "<br>")
document.write("Last Name:- "+person.lastName+"<br>")
document.write("Full Name:-"+person.fullName)
</script>
</head>
<body>
</body>
</html>
Output: -