-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart2.html
More file actions
102 lines (90 loc) · 3.3 KB
/
Copy pathpart2.html
File metadata and controls
102 lines (90 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Part 2: Integer Operations</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
}
form {
margin: 20px;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"] {
width: 100px;
}
textarea {
width: 100%;
height: 100px;
}
#result {
display: none;
}
</style>
</head>
<body>
<form id="calcForm">
<label for="num1">Enter Number 1:</label>
<input type="text" id="num1" name="num1" required>
<label for="num2">Enter Number 2:</label>
<input type="text" id="num2" name="num2" required>
<label for="num3">Enter Number 3:</label>
<input type="text" id="num3" name="num3" required>
<button type="button" id="calculate">Calculate</button>
<button type="button" id="clear">Clear</button>
<textarea id="result" readonly></textarea>
</form>
<!-- JavaScript Back Button -->
<button onclick="goBack()">Go Back to Homework 2</button>
<script>
$(document).ready(function () {
$('#calculate').click(function () {
// Get user inputs
var num1 = parseFloat($('#num1').val());
var num2 = parseFloat($('#num2').val());
var num3 = parseFloat($('#num3').val());
// Check if inputs are valid numbers
if (!isNaN(num1) && !isNaN(num2) && !isNaN(num3)) {
// Calculate operations
var sum = num1 + num2 + num3;
var average = sum / 3;
var product = num1 * num2 * num3;
var smallest = Math.min(num1, num2, num3);
var largest = Math.max(num1, num2, num3);
// Display results in the textarea
$('#result').val('Sum: ' + sum + '\n' +
'Average: ' + average + '\n' +
'Product: ' + product + '\n' +
'Smallest: ' + smallest + '\n' +
'Largest: ' + largest);
// Fade in the results
$('#result').fadeIn();
} else {
// Display error message if inputs are not valid numbers
$('#result').val('Error: Please enter valid numbers.');
// Fade in the error message
$('#result').fadeIn();
}
});
$('#clear').click(function () {
// Clear the form and hide the results
$('#calcForm')[0].reset();
$('#result').hide();
});
});
// JavaScript Back Button Function
function goBack() {
window.location.href = "homework2.html"; // Replace with the correct URL for Homework 2
}
</script>
</body>
</html>