-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.html
More file actions
41 lines (37 loc) · 1.46 KB
/
Copy pathArmstrong.html
File metadata and controls
41 lines (37 loc) · 1.46 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Armstrong Number Checker</title>
<script>
function isArmstrongNumber() {
const inputElement = document.getElementById("numberInput");
const resultElement = document.getElementById("result");
const number = parseInt(inputElement.value);
if (!isNaN(number)) {
const numString = number.toString();
const numDigits = numString.length;
let sum = 0;
for (let i = 0; i < numDigits; i++) {
const digit = parseInt(numString[i]);
sum += Math.pow(digit, numDigits);
}
if (sum === number) {
resultElement.textContent = `${number} is an Armstrong number.`;
} else {
resultElement.textContent = `${number} is not an Armstrong number.`;
}
} else {
resultElement.textContent = "Invalid input. Please enter a valid number.";
}
}
</script>
</head>
<body>
<label for="numberInput">Enter a number to check for Armstrong number:</label>
<input id="numberInput" type="text">
<button onclick="isArmstrongNumber()">Check Armstrong Number</button>
<p id="result"></p>
</body>
</html>