22761A4221 Module-4
22761A4221 Module-4
Module-4
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Ticket Booking</title>
<style>
div#maincontent {
height: 250px;
width: 500px;
text-align: left;
color: #08438E;
font-family: calibri;
font-size: 20;
padding: 5px;
div#heading {
text-decoration: bold;
text-align: center;
margin-top: 80px;
width: 500px;
text-align: center;
color: #08438E;
background-color: #CEE2FA;
font-family: calibri;
font-size: 20;
padding: 5px;
h2 {
padding: 0;
margin: 0;
</style>
</head>
<body>
<center>
<div id="heading">
<h2>Booking Summary</h2>
</div>
<div id="maincontent">
<script>
var ac=9;
var toc=0;
function calculateCost(n){
toc=ac*n;
calculateDiscount=(n)=>{
var cost=n*9;
var tc=0,n1=1,dis=5;
while(n1<=n)
var c=9-(9*(dis/100));
tc=tc+c;
n1=n1+1;
dis=dis+2;
document.write("</br>For "+n+" tickets you need to pay; $"+tc+" instead of: $"+cost);
if(n<2 || n>=5)
else
if(n==2)
calculateCost(n);
else
calculateCost(n);
calculateDiscount(n);
</script>
</div>
</center>
</body>
</html>
<html>
<head>
<title>Classes Demo</title>
<script>
class person {
constructor(name, age) {
super(name, age);
getDetails() {
document.write(`name:${this.name},</br>age:${this.age},</br>role:${this.role},</br>phone:${this.p
hone}`);
cObj1.getDetails();
</script>
</head>
</html>
4.c Course Name: Javascript.
Module Name: In-built Events and Handlers Write a JavaScript code to
book movie tickets online and calculate the total price based on the 3
conditions: (a) If seats to be booked are not more than 2, the cost per ticket
remains Rs. 150. (b) If seats are 6 or more, booking is not allowed.
<!DOCTYPE html>
<html>
<head>
<title>Booking Details</title>
<style>
div#maincontent {
height: 100px;
width: 500px;
text-align: left;
color: #08438E;
font-family: calibri;
font-size: 20;
padding: 5px;
margin-left: 10px;
div#heading {
text-decoration: bold;
text-align: center;
margin-top: 40px;
margin-left: 10px;
width: 500px;
text-align: center;
color: #08438E;
background-color: #CEE2FA;
font-family: calibri;
font-size: 20;
padding: 5px;
h2 {
padding: 0;
margin: 0;
</style>
</head>
<body>
<div id="heading">
<h2>Booking Summary</h2>
</div>
<div id="maincontent">
<script>
let discount = 5
var seat_cost = 9
let total=0
if(seat<=2){
document.write(seat*9);
else if(seat>=6){
else{
function calculateDiscount(seat) {
total+=discountamount;
discount+=2;
return ds
function calculatecost(seat){
return total_cost
}
document.write("</br>")
document.write("</br>")
document.write("</br>")
document.write("</br>")
</script>
</div>
</body>
</html>
4.d Course Name: Javascript.
Module Name: Working with Objects, Types of Objects, Creating Objects,
Combining and cloning Objects using Spread operator, Destructuring
Objects, Browser Object Model, Document Object Model If a user clicks
on the given link, they should see an empty cone, a different heading, and a
different message and a different background color. If user clicks again,
they should see a re-filled cone, a different heading, a different message,
and a differ.
<!DOCTYPE html>
<html>
<head>
<title>DOM API for HTML modification</title>
</head>
<body style="background-color:lightblue;text-align:center">
<h1 id="hdr1">Here's your ice cream</h1>
<img id="img1" src="i1.jpg" alt="Ice cream is not ready">
<p id="p1" onclick="eat()">Click here to eat</p>
<script>
function eat() {
var imgElement = document.getElementById("img1");
if (imgElement) {
var newSrc = "C:/Users/TEMP.WELAB48.000/Desktop/13.jpg";
imgElement.src = newSrc;
} else {
console.log("Image not found");
}
if (para) {
para.textContent = "Click to refill";
para.onclick = refill;
} else {
console.log("element not found");
}
function refill() {
var img = document.getElementById("img1");
if (img) {
var returnSrc = "i1.jpg";
img.src = returnSrc;
} else {
console.log("returning image not found");
}
</script>
</body>
</html>