Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

2.0 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
5675e877dbd60be8ad28edc6 Iterate Through an Array with a For Loop 1 使用For循环遍历数组

Description

JavaScript中的一个常见任务是遍历数组的内容。一种方法是使用for循环。此代码将数组arr每个元素输出到控制台:
var arr = [10,9,8,7,6];
forvar i = 0; i <arr.length; i ++{
ARR [I]的console.log;
}
请记住,数组具有从零开始的编号,这意味着数组的最后一个索引是长度 - 1.我们对此循环的条件i < arr.length ,当i长度为1时停止。

Instructions

声明并将变量total初始化为0 。使用for循环将myArr数组的每个元素的值添加到total

Tests

tests:
  - text: 应声明<code>total</code>并初始化为0
    testString: assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/));
  - text: <code>total</code>应该等于20
    testString: assert(total === 20);
  - text: 您应该使用<code>for</code>循环来遍历<code>myArr</code>
    testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/));
  - text: 不要直接将<code>total</code>设置为20
    testString: assert(!code.replace(/\s/g, '').match(/total[=+-]0*[1-9]+/gm));

Challenge Seed

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line

After Test

console.info('after the test');

Solution

// solution required