Increase language clarity in challenge "Basic Javascript: Iterate Through an Array with a For Loop" (#36081)
* Increase language clarity in the challenge. * Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.english.md Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * fix/make-suggested-changes-on-behalf-of-author * fix/add-empty-line-back-in
This commit is contained in:
		| @@ -16,7 +16,7 @@ for (var i = 0; i < arr.length; i++) { | ||||
| } | ||||
| ``` | ||||
|  | ||||
| Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our <dfn>condition</dfn> for this loop is <code>i < arr.length</code>, which stops when <code>i</code> is at length - 1. | ||||
| Remember that arrays have zero-based indexing, which means the last index of the array is <code>length - 1</code>. Our condition for this loop is <code>i < arr.length</code>, which stops the loop when <code>i</code> is equal to <code>length</code>. In this case the last iteration is <code>i === 4</code> i.e. when <code>i</code> becomes equal to <code>arr.length</code> and outputs <code>6</code> to the console. | ||||
| </section> | ||||
|  | ||||
| ## Instructions | ||||
| @@ -30,21 +30,19 @@ Declare and initialize a variable <code>total</code> to <code>0</code>. Use a <c | ||||
| ```yml | ||||
| tests: | ||||
|   - text: <code>total</code> should be declared and initialized to 0 | ||||
|     testString: assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/), '<code>total</code> should be declared and initialized to 0'); | ||||
|     testString: assert(code.match(/(var|let|const)\s*?total\s*=\s*0.*?;?/)); | ||||
|   - text: <code>total</code> should equal 20 | ||||
|     testString: assert(total === 20, '<code>total</code> should equal 20'); | ||||
|     testString: assert(total === 20); | ||||
|   - text: You should use a <code>for</code> loop to iterate through <code>myArr</code> | ||||
|     testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/), 'You should use a <code>for</code> loop to iterate through <code>myArr</code>'); | ||||
|     testString: assert(code.match(/for\s*\(/g).length > 1 && code.match(/myArr\s*\[/)); | ||||
|   - text: Do not set <code>total</code> to 20 directly | ||||
|     testString: assert(!code.match(/total[\s\+\-]*=\s*(0(?!\s*[;,]?$)|[1-9])/gm), 'Do not set <code>total</code> to 20 directly'); | ||||
|  | ||||
|     testString: assert(!code.match(/total[\s\+\-]*=\s*(0(?!\s*[;,]?$)|[1-9])/gm)); | ||||
| ``` | ||||
|  | ||||
| </section> | ||||
|  | ||||
| ## Challenge Seed | ||||
| <section id='challengeSeed'> | ||||
|  | ||||
| <div id='js-seed'> | ||||
|  | ||||
| ```js | ||||
| @@ -61,12 +59,10 @@ var myArr = [ 2, 3, 4, 5, 6]; | ||||
|  | ||||
| // Only change code below this line | ||||
|  | ||||
|  | ||||
| ``` | ||||
|  | ||||
| </div> | ||||
|  | ||||
|  | ||||
| ### After Test | ||||
| <div id='js-teardown'> | ||||
|  | ||||
| @@ -82,7 +78,6 @@ var myArr = [ 2, 3, 4, 5, 6]; | ||||
| ## Solution | ||||
| <section id='solution'> | ||||
|  | ||||
|  | ||||
| ```js | ||||
| var ourArr = [ 9, 10, 11, 12]; | ||||
| var ourTotal = 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user