Professional Documents
Culture Documents
LAB ASSIGNMENT-3
1. Design a web page to perform Arithmetic operation
CODE:
<!DOCTYPE HTML>
<head>
<style>
body{
background-color:lavender;
font-family:Cambria;
font-size:20px;
text-align:center;
border:2px solid black;
}
h3{
color:green;
text-decoration:underline;
}
</style>
<script language="javascript" type="text/javascript">
function multiply(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a*b;
document.my_cal.total.value=c;
}
function addition(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a+b;
document.my_cal.total.value=c;
}
function subtraction(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a-b;
document.my_cal.total.value=c;
}
function division(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a/b;
document.my_cal.total.value=c;
}
function modulus(){
a=Number(document.my_cal.first.value);
b=Number(document.my_cal.second.value);
c=a%b;
document.my_cal.total.value=c;
}
</script>
<title>Arithmetic operation</title>
</head>
<body>
<h3>19MID0132 Math calculator</h3>
<form name="my_cal">
Number 1: <input type="text" name="first">
<br>
<!-- Here user will enter 2nd number. -->
Number 2: <input type="text" name="second">
<br>
<input type="button" value="ADD" onclick="javascript:addition();">
<input type="button" value="SUB" onclick="javascript:subtraction();">
<input type="button" value="MUL" onclick="javascript:multiply();">
<input type="button" value="DIV" onclick="javascript:division();">
<input type="button" value="MOD" onclick="javascript:modulus();">
<br>
Get Result: <input type="text" name="total">
</form>
</body>
</html>
SCREENSHOT:
Addition
Subtraction:
Multiplication
Division
Modulo operation
2. Design a web page to read DOB and display age
CODE:
<!DOCTYPE html>
<html>
<head>
<title>Age Calculator</title>
<script>
function ageCalculator() {
var userinput = document.getElementById("DOB").value;
var dob = new Date(userinput);
if(userinput==null || userinput=='') {
document.getElementById("message").innerHTML = "**Choose a date
please!";
return false;
} else {
<body>
<div id="shapes">
<svg width='500' height='100'> <circle cx='50' cy='50' r='50'
style='stroke: none; fill: #FF8181;'/></svg>
</div>
<script type="text/javascript">
var cir=document.getElementById("circle");
var rec=document.getElementById("rectangle");
cir.addEventListener("mouseover",()=>{
document.getElementById("shapes").innerHTML = "<svg
width='500' height='100'><circle cx='50' cy='50' r='50' style='stroke:
none; fill: #CE00FF;'/></svg>";
});
cir.addEventListener("mouseout",()=>{
document.getElementById("shapes").innerHTML="<svg
width='100' height='100'><circle cx='50' cy='50' r='40' style='stroke:
none; fill:#FF8181;'/></svg>";
});
rec.addEventListener("mouseover",()=>{
document.getElementById("shapes").innerHTML="<svg
width='400' height='110'><rect width='300' height='100' style='stroke:
none; fill:#CE00FF;'/></svg>";
});
rec.addEventListener("mouseout",()=>{
document.getElementById("shapes").innerHTML="<svg
width='400' height='110'><rect width='300' height='100' style='stroke:
none; fill:#FF8181;'/></svg>";
});
</script>
</body>
</html>
SCREENSHOT:
5. Design a web page to show multiple mouse event handler on single
function
CODE:
<!DOCTYPE html>
<html>
<head>
<title>JS Mouse Events - Button Demo</title>
<style>
body{
background-color:lightblue;
text-align:center;
font-size:30px;
}
</style>
</head>
<body>
<button id="btn">Click me with any mouse button: left, right, middle,
...</button>
<p id="message"></p>
<script>
let btn = document.querySelector('#btn'); // disable context menu when
right-mouse clicked
btn.addEventListener('contextmenu', (e) => {
e.preventDefault();
}); // show the mouse event message
btn.addEventListener('mouseup', (e) => {
let msg = document.querySelector('#message');
switch (e.button) {
case 0:
msg.textContent = 'Left mouse button clicked.';
break;
case 1:
msg.textContent = 'Middle mouse button clicked.';
break;
case 2:
msg.textContent = 'Right mouse button clicked.';
break;
default:
msg.textContent = `Unknown mouse button code: ${event.button}`;
}
});
</script>
</body>
</html>
SCREENSHOT: