打印票号

问题描述 投票:-2回答:1

我想打印一些标准数字,范围在(32,321)之间,但不起作用。我正在使用此代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UFT-8">
  <title> </title>
</head>
<body>

    <script>
    function pares(x, y) {

    while (x<y){
        if((x%2) === 0){
            console.log(x)
            x++
        }
        else {
            return false
        }
    }
    }
    pares(32, 321);
    </script>
</body>
</html>

我只收到32。如何使它工作?

javascript
1个回答
2
投票

return语句会在遇到该函数后立即终止它。您在这里不需要返回语句。

function printEvenNumbers(x, y) {

    while (x < y) {
        if(x %2 === 0){
            console.log(x);
        }
        x++;
    }
 }

Visualize Execution Here

© www.soinside.com 2019 - 2024. All rights reserved.