由于某种原因,下面的代码不起作用,但我看不出它出错的地方......
for (number = 0; number <= 10; number ++1);{
var odd = number%2;
if (odd == true) {
console.log(number + " = even");
}
else {
console.log(number + " = oneven");
}
答案 0 :(得分:0)
有2或3个错误:
++
而不是++1
;
语句与for
之间的{
可能导致语法错误{}
答案 1 :(得分:0)
number++
。);{
。number % 2 === 0
是偶数)。for
循环。
for (number = 0; number <= 10; number++){
if (number % 2 === 0) {
console.log(number + " = even");
} else {
console.log(number + " = odd");
}
}
&#13;
答案 2 :(得分:0)
for (number = 0; number <= 10; number++);{//fixed here
var odd = number%2;
if (odd == 0) {//fixed here
console.log(number + " = even");
}
else {
console.log(number + " = oneven");
}
答案 3 :(得分:0)
存在大量错误
++1
&lt; - 意外号码
();
&lt; - 条件括号
}
&lt; - for循环缺少右括号
因此,如果数字为偶数%
将返回0
,其评估为false
因此您还必须撤消if
for (number = 0; number <= 10; number ++){
var odd = number%2;
if (odd == false) {
console.log(number + " = even");
}
else {
console.log(number + " = oneven");
}
}