这个功能出了什么问题?我想将1添加到c_count,直到达到100
<script type="text/javascript"> var result = cMat(0); function cMat (c_count) { var limit = 100; match = 1; while (c_count != limit) c_count ++ match; if (c_count == 95) { c_count = 10; } } return (c_count) } </script>
答案 0 :(得分:0)
我想在c_count中添加1,直到达到100
每次达到95时,您都会将c_count
重置为10,因此它永远不会达到您的限制。您的匹配变量似乎没有被使用,因此可以将其删除。要检查的一件事是c_count的值相对于100.如果它大于100,则需要递减值而不是递增它。
var result = cMat(0);
function cMat (c_count) {
var limit = 100;
while (c_count != limit)
if(c_count < limit) {
c_count++;
} else { // Implied that it's greater than the limit at this point
c_count--;
}
}
return c_count;
}