0% found this document useful (0 votes)
24 views4 pages

Lab 6 Web

The document contains code for 4 JavaScript tasks that perform basic mathematical operations like calculating area of a triangle, multiplying and dividing numbers, finding the maximum of two numbers, and adding, subtracting, multiplying and dividing two numbers.

Uploaded by

ameenayaqoob4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Lab 6 Web

The document contains code for 4 JavaScript tasks that perform basic mathematical operations like calculating area of a triangle, multiplying and dividing numbers, finding the maximum of two numbers, and adding, subtracting, multiplying and dividing two numbers.

Uploaded by

ameenayaqoob4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ameena Yaqoob

Uw-21-cs-bs-040

Task:01
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">


<head>
<meta charset="utf-8" />
<title>lab 6 task 1</title>
</head>
<script>
function area() {
base = 5;
height = 6;
area = 1 / 2 * base * height;
document.write("base: " + base + "<br>");
document.write("height: " + height + "<br>");
document.write("area of triangle: " + area);
}
</script>
<body>
<button onclick="area()">Click here for area of triangle</button>
</body>
</html>

Task:02
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>lab 6 task 2</title>
</head>
<body>
<script>
function multiply() {
var num1 = document.getElementById("firstnumber").value;
var num2 = document.getElementById("secondnumber").value;
document.getElementById("result").innerHTML = num1 * num2;
}
function divide() {
var num1 = document.getElementById("firstnumber").value;
var num2 = document.getElementById("secondnumber").value;
document.getElementById("result").innerHTML = num1 / num2;
}
</script>
<form>
1st number: <input type="text" id="firstnumber"><br>
2nd number: <input type="text" id="secondnumber"><br>
<input type="button" onclick="multiply()" value="multiply">
<input type="button" onclick="divide()" value="divide">
</form>
<p>
THE RESULT IS:
<span id="result"></span>
</p>
</body>
</html>

Task:03
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>lab 6 task 3</title>
</head>
<body>
<script>
function maximum() {
var num1 = parseFloat(document.getElementById("firstnumber").value);
var num2 = parseFloat(document.getElementById("secondnumber").value);
if (num1 > num2) {
document.getElementById("result").innerHTML = num1;
}
else {
document.getElementById("result").innerHTML = num2;
}
}

</script>
<form>
1st number: <input type="text" id="firstnumber"><br>
2nd number: <input type="text" id="secondnumber"><br>
<input type="button" onclick="maximum()" value="Maximum number">
</form>
<p>
The Maximum Number Is:
<span id="result"></span>
</p>
</body>
</html>
Task:04
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>lab 6 task 4</title>
</head>
<body>
<script>
function multiply() {
var num1 = parseFloat(document.getElementById("firstnumber").value);
var num2 = parseFloat(document.getElementById("secondnumber").value);
document.getElementById("result").innerHTML = num1 * num2;
}
function divide() {
var num1 = parseFloat(document.getElementById("firstnumber").value);
var num2 = parseFloat(document.getElementById("secondnumber").value);
document.getElementById("result").innerHTML = num1 / num2;
}
function add() {
var num1 = parseFloat(document.getElementById("firstnumber").value);
var num2 = parseFloat(document.getElementById("secondnumber").value);
document.getElementById("result").innerHTML = num1 + num2;
}
function subtract() {
var num1 = parseFloat(document.getElementById("firstnumber").value);
var num2 = parseFloat(document.getElementById("secondnumber").value);
document.getElementById("result").innerHTML = num1 - num2;
}
</script>
<form>
1st number: <input type="text" id="firstnumber"><br>
2nd number: <input type="text" id="secondnumber"><br>
<input type="button" onclick="multiply()" value="multiply">
<input type="button" onclick="divide()" value="divide">
<input type="button" onclick="add()" value="add">
<input type="button" onclick="subtract()" value="subtract">
</form>
<p>
THE RESULT IS:
<span id="result"></span>
</p>
</body>
</html>

You might also like