js基础

ji-求用户输入最大值

2019-04-27  本文已影响0人  椋椋夜色

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>求用户输入最大值</title>

<script>
    var max = -Infinity;
    for (var i = 1; i <= 3; i++) {
        var shu = +prompt('请输入3组数字计算最大值 第' + i + '组');
        if (shu > max) {
            max = shu;
        }
    }
    alert('最大值为:' + max);

    var max = Infinity;
    for (var i = 1; i <= 3; i++) {
        var shu = +prompt('请输入3组数字计算最小值 第' + i + '组');
        if (shu < max) {
            max = shu;
        }
    }
    alert('最小值为:' + max);
</script>

</head>

<body>

</body>

</html>

上一篇下一篇

猜你喜欢

热点阅读