Practical – 118.2 : Sum of All Given Digits
Program Code :
<!DOCTYPE html>
<html>
<head>
<title>Sum of Digits</title>
<style>
body {
font-family: Arial;
text-align: center;
margin-top: 50px;
}
input, button {
padding: 10px;
font-size: 16px;
margin: 5px;
}
</style>
</head>
<body>
<h2>Sum of All Given Digits</h2>
<input type=”number” id=”numberInput” placeholder=”Enter a number”>
<button onclick=”sumDigits()”>Calculate Sum</button>
<h3 id=”result”></h3>
<script>
function sumDigits() {
let number = document.getElementById(“numberInput”).value;
let sum = 0;
for (let digit of number) {
sum += parseInt(digit);
}
document.getElementById(“result”).innerText = “Sum of digits: ” + sum;
}
</script>
</body>
</html>