JavaScript:反向输出三位数(正整数)
问题描述
输入一个三位正整数,输出时反向输出。例如,输入345,输出543。
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var n = parseInt(window.prompt('Please enter a three-digit integer: '));
var result;
if(n >= 0 && n < 1000){
var a = n % 10;
var b = (n - a) / 10 % 10;
var c = (n - a - b * 10) / 100 % 10;
result = a * 100 + b * 10 + c;
document.write('the result is: ' + result);
}else{
document.write('error');
}
</script>
</body>
</html>
|