例如输入508就输出5+0+8的和13;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
//输入三位数求其和
//第一步转为数字类型
var g = prompt("请输入一个三位数");
var gg = parseInt(g);
//155/100=1.55 取1
var h = parseInt(gg/100);
//155%100=1...55,55/10=5.5 取5
var i = parseInt(gg%100/10);
// 155&10=15...5
var j = parseInt(gg%10);
var k = h+i+j;
console.log(k)
</script>
</body>
</html>
这个程序的关键就是求十位数,百位和个位都能想到