for循环。此代码将数组arr每个元素输出到控制台: var arr = [10,9,8,7,6];请记住,数组具有从零开始的编号,这意味着数组的最后一个索引是长度 - 1.我们对此循环的条件是
for(var i = 0; i <arr.length; i ++){
(ARR [I])的console.log;
}
i < arr.length ,当i长度为1时停止。 total初始化为0 。使用for循环将myArr数组的每个元素的值添加到total 。 total并初始化为0
testString: 'assert(code.match(/var.*?total\s*=\s*0.*?;/), "total should be declared and initialized to 0");'
- text: total应该等于20
testString: 'assert(total === 20, "total should equal 20");'
- text: 您应该使用for循环来遍历myArr
testString: 'assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/), "You should use a for loop to iterate through myArr");'
- text: 不要直接将total设置为20
testString: 'assert(!code.match(/total[\s\+\-]*=\s*(\d(?!\s*[;,])|[1-9])/g), "Do not set total to 20 directly");'
```