All or Nothing explainer

I got it, thank you very much!

2 Likes

It’s not working for me

2 Likes

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.
Ben

2 Likes

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.

2 Likes

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

double(5)

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!
-Ben

4 Likes

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

4 Likes

What did I do wrong?

1 Like

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!
Ben

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,
Ben

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.

Ben

2 Likes

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.

1 Like

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.
Ben

3 Likes

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

3 Likes

Guys, amazing task! Thank you for that!


_

Really got stopped for a few. It was the most hardcore puzzle since I started.

Can I ask? Why you (I mean app :)) doesn’t agree with another ways of solution?!

My first solution stopped by the program - as too much recombination in first code… So It makes me mad. It may be a little bit unhappy for another IT-brains I guess = to find another solution and got… Nothing! (Fantastic unbelievable unforgettable nothing) or restart of the task :). Why the Justice League didn’t say anything?

On the one hand, I realize, why needed only one-way-answer.

On the other… Avengers, help!

If program do what you need, and you’ve got 2 solutions or more - why not?

Sorry, If I’m too romantic, but - programming is a way to solve the problems. You may do it elegance or like dishes-dancing elephant, but you find ways to get whatever you needed. I mean, you may find a long field of difference solutions, so why we’ve learning to see just one?

(I understand, that answer from guru with great experience is not equal to new member.

But answer me, please:

  • Why don’t Grasshopper get more points - for 2 or more solutions? For me, It’s upset.

  • At level 1, while you reached Moon (!!!) after last exercise - would be better to get more animation. Like green popping + new colour or many colours. Maby more energetic music?

I tried to say: steps from exercise to exercise looks great, in compliance with Moon - they got 100 from 100. I love the idea of travel-game, so why we’ve got so silence on the top? It might be party hard ^^.

  • Last great thoughts:

The Grasshopper is amazing!
I dreamed about getting this magic experience… But can’t even imagine that it would be in so useful, fast, interesting, beautiful and comfortable way.
Thank you from all my heart!

P.S. Hope to see exercises in other languages or maybe just added here.

More interesting experience is to learn more: for instance, second programming language - to get parallel vision of them, life get colour :wink: with deep understanding the bright moment’s hesitation - when you realize how to do, and even better, also I love to complete puzzles. Once upon a time I heard that best brains could use 2 and more languages to get the best solutions. And languages for them are like instrument panel - both may be using, both do. But one of them could do… it with a sense of humour :slight_smile:

Remember: the right answer you even once didn’t get from me or others. Shame on you! (*I mean:)
42.

1 Like

:exploding_head:

Glad you’re enjoying programming!
-Ben

3 Likes

A post was merged into an existing topic: Split Up Evenly explainer