-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp3.html
More file actions
34 lines (29 loc) · 879 Bytes
/
Copy pathexp3.html
File metadata and controls
34 lines (29 loc) · 879 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Find Largest Number</title>
</head>
<body>
<h3>Enter numbers separated by commas:</h3>
<input id="inputNumbers" type="text" placeholder="e.g. 4,5,1,8">
<button onclick="showLargest()">Find Largest</button>
<p id="result"></p>
<script>
function findLargest(numbers) {
let largest = numbers[0];
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] > largest) {
largest = numbers[i];
}
}
return largest;
}
function showLargest() {
const input = document.getElementById('inputNumbers').value;
const arr = input.split(',').map(num => Number(num.trim()));
const largestNum = findLargest(arr);
document.getElementById('result').textContent = "Largest number: " + largestNum;
}
</script>
</body>
</html>