Challenge: Iterate through an array with a for loop (Make test and requirements stricter)
See original GitHub issueThis challenge can be passed with incorrect code. It does not check that the array elements are added to total
.
var total = 0;
for (total; total < 20; total += myArr[0]) { }
var total = 0;
for (var i = 0; i <= 20; i++) {
myArr[0];
total = i;
}
var total = 0;
for (var i = 0; i <= myArr[3] * 4; i++) {
total = i;
}
The requirements should probably be stricter and expect either total += myArr[i]
or total = total + myArr[i]
to be inside the body of the for loop (without forcing the iterator variable name to be i
).
Forum post: https://forum.freecodecamp.org/t/iterate-through-an-array-with-a-for-loop-challenge-help/495925
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Iterate Through an Array with a For Loop - Guide
Initialization: i gets a value of 0 and its used as a counter. · Condition: the subsequent code is executed as long as...
Read more >Ways of iterating over a array in JavaScript - GeeksforGeeks
In this article, we will learn, we will learn how to iterate over an array using JavaScript, there are multiple ways to do...
Read more >Using a for loop with a function in Javascript [closed]
Complete the function droids that accepts an array of strings and iterates through the array using a FOR loop. Update the variable result...
Read more >Iterate Through an Array with a For Loop - Free Code Camp
In today's basic JavaScript tutorial we will be iterating through an array with a for loop. This is one video of many where...
Read more >For loop with Array Challenge (Example) - Treehouse
The task was to "Use a for or while loop to iterate through the values in the temperatures array from the first item...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On each iteration we can check the condition and return according statement
var total = 0; function iterate(arr){ for(let i = 0 ; i < arr.length; i++){ if (total !=total + arr[i]){ total += arr[i];} }
Challenge is being rewritten for the new curriculum so closing it.