我想打印一些标准数字,范围在(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。如何使它工作?
return
语句会在遇到该函数后立即终止它。您在这里不需要返回语句。
function printEvenNumbers(x, y) {
while (x < y) {
if(x %2 === 0){
console.log(x);
}
x++;
}
}