我确信这与早上5点左右有关...我错过了一些明显的东西。
这是我的代码:
var dayInMonth = 2,
lastDayNum = 30;
console.log(dayInMonth, (dayInMonth > lastDayNum)); // displays "2 false"
for(dayInMonth; dayInMonth > lastDayNum; dayInMonth++){
console.log("here!") // not displaying anything
}
什么阻止for循环执行console.log()
语句?
答案 0 :(得分:1)
dayInMonth > lastDayNum
永远不会更大
答案 1 :(得分:1)
dayInMonth > lastDayNum
应为dayInMonth <= lastDayNum
,对吧?
答案 2 :(得分:1)
for(dayInMonth; dayInMonth < lastDayNum; dayInMonth++){
alert("here!") // not displaying anything
}
你想&lt;不是&gt;。
答案 3 :(得分:1)
尝试
dayInMonth < lastDayNum
只要第二个参数为真,就执行for循环,直到它为假。
答案 4 :(得分:1)
var dayInMonth = 2,
lastDayNum = 30;
console.log(dayInMonth, (dayInMonth > lastDayNum)); // displays "2 false"
for(dayInMonth; dayInMonth < lastDayNum; dayInMonth++){
console.log("here!") // not displaying anything
}
Inside for&lt;,not not gt;
答案 5 :(得分:1)
错误的逻辑测试(&lt;而不是&gt;);
for(; dayInMonth < lastDayNum; dayInMonth++){
console.log("here!") // not displaying anything
}