Untitled

mail@pastecode.io avatar
unknown
html
2 years ago
620 B
1
Indexable
<!DOCTYPE html>
<html>
<head>
	<title>Question 1</title>
</head>
<body>

	<label>Enter Number:</label>
	<input type="text" name="number" id="number">
	<br>
	<label>Summation</label>
	<input type="text" name="result" onclick="sum()" id="result">



	<script type="text/javascript">
	function sum(){
		let digits = document.getElementById('number').value;
		let number = parseInt(digits);
		let sum = 0;
		let rem;

		while(number!=0){
			rem=number%10;    
			sum=sum+rem;    
			number=number/10; 
		}
		document.getElementById("result").value = sum;
		
	}
</script>

</body>


</html>