<!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>
</body>
<script>
// 输入三个数,输出最大的那个数
// alert("请输入三个数");
var first = parseInt(prompt("请输入三个数\nPlease input first numbers:"));
var second = parseInt(prompt("Please input second numbers:"));
var third = parseInt(prompt("Please input third numbers:"));
// 如果三个数值判断是""或null或NaN就直接返回非数值。
if ((first == "" || first == null || isNaN(first) == true) || (second == "" || second == null || isNaN(second) == true) || (third == "" || third == null || isNaN(third) == true)) {
alert("您输入是非数字!!");
} else {
var max;//创建一个临时变量
// 如果第一个数比第二个数大
if (first > second) {
// 第一个数跟第三个数比较
if (first > third) {
max = first;
} else {
max = third;
}
} else {
//第二个数跟第三个数比较
if (second > third) {
max = second;
} else {
max = third;
}
}
alert("最大值为:" + max);
}
</script>
</html>
js输入三个数输出最大的
最新推荐文章于 2023-09-19 19:13:47 发布