question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Challenge: Iterate through an array with a for loop (Make test and requirements stricter)

See original GitHub issue

This 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).


Challenge: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop

Test: https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md

Forum post: https://forum.freecodecamp.org/t/iterate-through-an-array-with-a-for-loop-challenge-help/495925

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hrushi2003commented, Feb 16, 2022

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];} }

0reactions
Nirajn2311commented, Aug 3, 2022

Challenge is being rewritten for the new curriculum so closing it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found