All or Nothing explainer

From what I can tell I think I’m doing it correctly

I also tried making the second return statement an if statement to see if that would work but I got the same result

@Bre_Anna_Bailey — thanks for sharing!

The second return statement is inside the for loop, rather than after.

This is a really easy error to make (that professional programmers often do). A good way to check that your code is in the correct place is to match up code blocks (in this case curly brackets {}) from the bottom up, matching every bottom bracket with a top bracket.

Looking at the bottom of your code we can see the bottom-most curly bracket is just above the console.log() statement. This corresponds to see the first opening bracket of the function declaration. That means this bottom-most curly bracket is the end of the function declaration.

If we go up one line from the bottom, we can see another curly bracket — what is this the closing bracket for? That is the closing bracket for the for loop.

That means the return statement should come after that curly bracket, but before the final curly bracket that closes the function declaration. Right now your code will return after looking at the first element in the array; but we want it to keep looping if the test is not ‘fail’.

Your function should look something like this:

function check(results) {
   for (var test of results) {
      if (test === 'fail') {
       return 'failed'
  return results.length +' tests passed.'

I hope this helps a little!

H :slight_smile:

1 Like

I got it, thank you very much!

It’s not working for me

Hey there,

In your if statement, you’re testing if the string 'test' is equal to the string 'fail'.

Let’s take a look at how the function works.

The check() function takes an array of strings, which is represented by the results parameter.

It then loops through results to look at each string individually. On every loop, the current string is represented by the element variable.

Use this variable in your if statement instead of the string 'test' that you were using before. It will look like this:

for (var element of results) {
    if (element === 'fail') {
        return 'failed';

That should work. Let me know if you have any questions or encounter any other difficulty.

Hello, my results is working but it seems there is a problem and I can’t understand why.
Both of my returns are right in place.

Hey there,

Your check function has a parameter called results, but that parameter isn’t being used anywhere in the function. You are instead using testResults, which we want to use as the argument when the function is called.

A quick refresher on parameters vs arguments:

When a function is declared, a parameter can be added inside the parentheses (not all functions require parameters). This parameter is like a special variable that lives inside the function. When the function is called, whatever is passed in as an argument will behave like the parameter.

For example:

function double(num) {
    return num * 2;


In the above example, num is the parameter, while 5 is the argument.

Hope this clears things up! Let me know if you have any questions!

1 Like

Hey Ben ! Thank for your patience.
I knew the difference between the parametre and argument but it wasn’t enough.

Sometimes we need to repeat before it’s sticks. :slight_smile:
Thank you so much

1 Like

What did I do wrong?

Hey there, it looks like the testResults inside the import statement was renamed to Results. Because there isn’t anything in 'grasshopper.laboratory' named Results, this means nothing is being imported.

Try resetting the puzzle to set the names back, then try your solution again. That should solve the problem.

Hope this helps!

It did not help

This is really important!

Hey there, it looks like there is still Results with a capital R in the import statement. This is causing the issue, because it should be testResults.

To fix this, tap the reset button to change the import statement back. It’s the button that looks like a circular arrow (like the refresh button on a browser). Then try the puzzle again.

Let me know if you have any questions,

This is not working can you just send me the correct code

Could you please help me?

Hey there, the solution code is now posted at the top of this thread. Take a look, and let me know if you have any questions.


I’m not totally sure what I’m doing wrong. I’ve looked at all the feedback and I can’t figure out if there’s something in the wrong place or what.

Hey there,

The function takes a parameter, results, and loops through it, looking at each item one at a time. If one of those items is the string 'fail', the function will return the string 'failed'. Otherwise it will return the length of results.

When the function is called, it takes testResults as an argument.

In your code, testResults is being used where you should be using results. Change your for loop to this:

for (var element of results) {
    if (element === 'fail') {
        return 'failed';

Then, at the end of the function:

return results.length + 'tests passed';

Hope this helps! Let me know if you have any questions.

Thank you! That helps a lot! I completed it.

1 Like