Skip to content

Instantly share code, notes, and snippets.

@danielef
Created August 7, 2013 22:10
Show Gist options
  • Save danielef/6179274 to your computer and use it in GitHub Desktop.
Save danielef/6179274 to your computer and use it in GitHub Desktop.
input {
padding: 5px;
width: 90%;
}
div {
padding: 5px;
width: 100%;
}
button {
width: 90%;
}
<html>
<head>
<title>Problema 3</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
</head>
<body>
<div>
<input type="text" id="n" value="123"/>
</div>
<div>
<button id="e">evaluar entero</button>
</div>
<div>
<input type="text" id="a"/>
</div>
</body>
</html>
$(document).ready(function() {
$("#e").click(function() {
$("#a").val(sum($("#n").val()));
});
});
function sum(n) {
return (n === 0) ? 0: n%10 + Math.floor(sum(n/10));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment