VB icon

Sum of Digits in JavaScript

Email
Submitted on: 5/22/2016 1:54:08 AM
By: Jake R. Pomperada  
Level: Beginner
User Rating: Unrated
Compatibility: JavaScript
Views: 4571
author picture
 
     A simple program that I wrote using JavaScript as my programming language that will ask the user to give a number and then our program will add the sum of digits in a given number by our user. The code is very to understand. Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com My mobile number here in the Philippines is 09173084360.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Sum of Digits in JavaScript
' Description:A simple program that I wrote using JavaScript as my programming language that will ask the user to give a number and then our program will add the sum of digits in a given number by our user. The code is very to understand.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
My mobile number here in the Philippines is 09173084360.
' By: Jake R. Pomperada
'**************************************

<!DOCTYPE html> 
<html>
<head> 
<meta charset=utf-8 /> 
<title>Sum of Digits in JavaScript</title> 
<style type="text/css"> 
body {
font-family:arial;
	font-size:12;
	font-weight:bold;
background-color:lightgreen;
	margin: 30px;
	}
</style>
</head> 
<body> 
<script>
function Sum_of_Digits() {
 var number = document.getElementById("number1").value;
 var str = number.toString();
 var sum = 0;
 for (var i = 0; i < str.length; i++) {
sum += parseInt(str.charAt(i), 10);
 }
document.getElementById("result").innerHTML = sum;
}
</script>
<hr>
<h2>Sum of Digits in JavaScript </h2>
 <hr>
<form> 
Enter a number <input type="text" id="number1" maxlength="10" size="10"><br> 
<br>
<input type="button" onClick="Sum_of_Digits()" Value="Ok" 
title="Click here to find the total sum of digits of a number." />  
</form> <br>
<p>The total sum of digits is : 
<span id = "result"></span> 
</p> 
</body> 
</html>


Other 108 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.