"Run the Tests" button isn't working

"Run the Tests" button isn't working
0.0 0

#1

Tell us what’s happening:

“Run the Tests” button isn’t working. On clicking nothing is happening. Tried both in Chrome and Firefox.

Your code so far


function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for(var i = 0; i < arr.length; i++)
    for(var j = 0; j < arr[i].length; j++)
      product *= arr[i][j];
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/nesting-for-loops/


#2

i am not up to js yet, but if you take your for loops out it runs, my best guess is there is a syntax error

for(var i = 0; i < arr.length; i++)
for(var j = 0; j < arr[i].length; j++)
product *= arr[i][j];
// Only change code above this line
return product;

isn’t there supposed to be curly brackets?
https://www.w3schools.com/js/js_loop_for.asp


#3

No, it’s okay to not to have curly braces if there are one statement inside. Anyway, if that’s a syntax error it should show errors in the console, isn’t it?


#4

It was because of the curly braces. Putting them, accepted the answer. May be it’s a bug of freecodecamp. I tried that code without curly braces with my local file and got expected result. Thanks man!


#5

Yeh thats what i read online too, but it seems from my understanding the rule is the statement has to be right after the for/if/else conditions rather then a nested for loop. For testing purposes with the code you have remove one of the for() lines so its not nested and the run button will work.


#6

@heisenberg.pb

This is because you have multiple statements. A for loop with only one statement works without braces, but will fail if it has multiple.

The best way to tell without a linter if you can omit the braces, is that they must be single line. The same is true for if statements.

// does not work, multiple statements
for(var i = 0; i < arr.length; i++)
    for(var j = 0; j < arr[i].length; j++)
      product *= arr[i][j];

if (true)
  if (somethingElse)

// does work, braces for multiple statements, none for the single line one
for(var i = 0; i < arr.length; i++) {
    for(var j = 0; j < arr[i].length; j++) product *= arr[i][j];
  }

if (true) return 'yay'

#7

First I tried with browser console. Worked perfect:
1

Then I tried with normal writing scripts inside HTML file. No problem either:
2

Output in the console of the above code:
3

So, it’s okay to have no curly braces till all nested loops or if-else statements has one statement.
Here, the first for has only one for loop and the second one has only one statement.