This repository was archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtask10.html
130 lines (113 loc) · 4 KB
/
task10.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Function Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
background-color: #ffffff;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
font-weight: bold;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="number"] {
width: 100%;
padding: 5px;
border: 1px solid #cccccc;
border-radius: 4px;
}
select {
width: 100%;
padding: 5px;
border: 1px solid #cccccc;
border-radius: 4px;
}
.result {
margin-top: 20px;
background-color: #f9f9f9;
border: 1px solid #cccccc;
padding: 10px;
white-space: pre-wrap;
font-family: monospace;
font-size: 14px;
}
</style>
</head>
<body>
<div class="container">
<h1>Function Calculator</h1>
<form id="functionForm">
<label for="functionSelect">Select a function:</label>
<select id="functionSelect" required>
<option value="">-----Select-----</option>
<option value="linear">Linear (x)</option>
<option value="inverse">Inverse (1/x)</option>
<option value="log">Log (log(x))</option>
</select>
<label for="numberInput">Enter a number:</label>
<input type="number" id="numberInput" required>
<button type="submit">Submit</button>
</form>
<div class="result" id="resultContainer"></div>
</div>
<script>
document.getElementById("functionForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent form submission
var functionSelect = document.getElementById("functionSelect");
var selectedFunction = functionSelect.value;
var numberInput = document.getElementById("numberInput");
var number = parseFloat(numberInput.value);
if (selectedFunction === "inverse" && number === 0) {
alert("Wrong input: Cannot divide by zero");
return;
}
if (selectedFunction === "log" && (number <= 0 || isNaN(number))) {
alert("Wrong input: Input must be a positive number");
return;
}
var result;
switch (selectedFunction) {
case "linear":
result = number;
break;
case "inverse":
result = 1 / number;
break;
case "log":
result = Math.log(number);
break;
default:
result = "Unknown function";
break;
}
var resultContainer = document.getElementById("resultContainer");
resultContainer.textContent = "Result: " + result;
var formData = {
selectedFunction: selectedFunction,
number: number,
result: result
};
var json = JSON.stringify(formData, null, 2);
resultContainer.textContent += "\n\n" + json;
});
</script>
</body>
</html>