JS输入一个小于10的正整数(for循环和逻辑分析)
发布网友
发布时间:2022-04-24 11:43
我来回答
共2个回答
热心网友
时间:2022-04-24 13:12
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>test</title>
<script type="text/javascript">
var guys = function ()
{
var max = Number.MIN_VALUE, min = Number.MAX_VALUE;
for ( var i = 0; i < 3; i++)
{
var number = prompt ("输入第 " + (i + 1) + " 个小于10的正整数: ", "");
if (isNaN (parseFloat (number)) || !isFinite (number))
{
alert ('输入非法,重新输入.');
i--;
continue;
}
max = max < number ? number : max;
min = min > number ? number : min;
}
alert ("最大值是:" + max + "\n最小值是: " + min);
}
guys ();
</script>
</head>
<body>
</body>
</html>
热心网友
时间:2022-04-24 14:30
你想干嘛啊,说清楚