Poland to San Marino explainer

The aim of this puzzle: Turn the Polish flag into the flag of San Marino.

Walkthrough of the solution: The first line of code creates a variable called stripeColor and gives it a starting value of white. That means the next three drawBox(stripeColor) will draw white boxes.

Then there’s a line that says stripeColor = red which changes the value stored inside of stripeColor to the color red. Then there are three more drawBox(stripeColor) commands. If you run the code the first time, you’ll see that the bottom stripe is red and you want it to be blue. So, you need to make sure the last three drawBox() commands are getting a value of blue.

Instead of changing each stripeColor into blue, you can simply change the line that assigns red to stripeColor into stripeColor = blue. Then, every time you use stripeColor after that, drawBox(stripeColor) will run the same as drawBox(blue) unless the value of stripeColor changes again later in your code.

The boxes you already drew won’t change their color – once you draw them, they’re locked in.

Sample code solution:
(Tap below to reveal)

var stripeColor = white;
drawBox(stripeColor);
drawBox(stripeColor);
drawBox(stripeColor);
newLine();
stripeColor = blue;
drawBox(stripeColor);
drawBox(stripeColor);
drawBox(stripeColor);

JavaScript Concepts: Assignments, Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: drawBox()

5 Likes

My written code looks exactly like the sample revealed, but I keep getting a message that there is an extra var over and over. and then to reset. I can’t get to the next level. There is no extra var. Glitch?
How do I get past this? Thank you in advance for any solution. —JB

4 Likes

hello there i am a beginner and i made the exact same mistake you did
the thing is for the second time i think you used var x = red instead of just x=red…
hope it helps

im sorry about the colors…my bad

5 Likes

Thank you, parth_shah , Kind regards, JB

1 Like

I cant seem to do this for some reason.

2 Likes

Excuse me please, I tried a lot of times that exercise but it’s impossible for me resolve it. I don’t understand the bad step. Can you suggest me any clue? Thank you very much!

2 Likes

Hey there,

The first line declares a variable called x and gives it the value white.
The first 3 drawBox() function calls create white boxes, because x is white.

On the 5th line, the value of x is changed to blue. We don’t need to use the var keyword again because we’re just changing the value of a variable, not creating a new one.

Hope this helps!
Ben

1 Like

Thank you very much Sir. I can succeed the exercise!

1 Like

It says it already from the instruction, change red to blue, all you have to do it Edit code x = red into x = blue.
hope that works…

1 Like

I have no clue how to get past the level either.

1 Like

What is it that you don’t understand :)?

I Don’t Understand Stil?

I have written the same code that the solution but I still have the following message: "The variable declaration var stripeColor = white does not need to be changed, but the variable update stripeColor = red does. Try changing the update to stripeColor = blue ".

There is no stripeColor = red, it seems there is no use for var stripeColor = in the solution!!!

A precision, it’s in the Web version that this problem exists, in mobile versions the puzzle is Haïti to Ukraine and it works there!

I can’t pass this level need help

Hey there,

We recently changed the variable name from x to stripeColor, as there was some confusion over what the variable was being used for.

If you’ve opened the puzzle in the past and are revisiting it after the change, the app/website will load your old starter code that has the variable x. To fix this issue, just tap/click the reset ⟳ button.

@Feast_Gamer69 Try posting a screenshot of your code, and I’ll take a look!

Hope this helps!
Ben

1 Like

I have been practicing some codes as a new member but I don’t really seem to understand what’s wrong with this practical sample.

Kindly help identify the error and explain how to handle such error.

Thanks so so much

1 Like

Try inserting the color names as strings :slight_smile:

Hey there, try using the reset button ⟳ on the code keyboard to reset the puzzle. That will change the variable name back to stripeColor. You’ll then get better error messages that will guide you to the solution.

Hope this helps!
Ben

1 Like

Keep saying there’s and extra verb,I wont to now where am doing mistake…pliz help