# Haiti to Ukraine explainer

The aim of this puzzle: Turn the Haitian flag into the Ukrainian flag.
Walkthrough of the solution: The first line of code creates a variable called `x` and gives it a starting value of `blue`. That means the next three `drawBox(x)` will draw blue boxes. Then there’s a line that says `x = red` which changes the value stored inside of `x` to the color `red`. Then there are three more `drawBox(x)` commands. If you run the code the first time, you’ll see that the bottom stripe is red and you want it to be yellow. So, you need to make sure the last three `drawBox()` commands are getting a value of `yellow`. Instead of changing each `x` into `yellow`, you can simply change the line that assigns `red` to `x` into `x = yellow`. Then, every time you use `x` after that, `drawBox(x)` will run the same as `drawBox(yellow)` unless the value of `x` 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 x = blue;
drawBox(x);
drawBox(x);
drawBox(x);
newLine();
x = yellow;
drawBox(x);
drawBox(x);
drawBox(x);
``````

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

3 Likes

Why can’t we use two variables in single code

1 Like

Hey @Sridhar_Reddy,

The aim of this puzzle is to change a variables value. If you create a new variable, you’re not changing the other variable’s value.

To change a variable’s value you don’t need to use the `var` key, rather assign it a new value using the `=` key. Like: `x = yellow`.

I’m hoping this helps!
H

2 Likes

If solution for this problem was word then

Then this should become Y but why was solution shows 5 as correct

x = 5 because 5 is the value of y. When you assign a variable to another variable, it takes the value. In your first picture (with alphabet = ‘word’;), alphabet is not assigned the variable word but the string ‘word’. If alphabet was assigned to the variable word, then alphabet would be assigned to the value of word, ‘alphabet’.
I Hope this helps and doesn’t confuse you more

5 Likes

Hi! Basically “print” is trying to look up the variables assigned. Javascript will read it out like this image.

1 Like

Why is a var command not needed for the second x?

`var` is used to define a new variable. Once the variable is created, you no longer have to use `var` to use or change the variable later in the program.

Hope this helps! Feel free to reply if otherwise, and I can try to go more in-depth!

3 Likes

Nope that explains it perfectly! Thanks so much! I haven’t coded since the 80’s (BASIC), so this is exciting to get back into it again.

3 Likes

‘alphabet’ is a string in the above case and
Var alphabet is a variable…

In the example it says that its red, yet its yellow. Am I missing something?

1 Like

Same here, therfore i can’t solve this step.

1 Like

Hey @Rob_Peebles,

Can you share a screenshot of your code? That way we can have a look to see if it matches the solution for this puzzle?

H

I may add some words to the brilliant explanations we have here:
The importance of the var comand is that, when you declare a variable, the computer needs to know that some space needs to be reserved in memory for data to be stored in that variable.
So that’s achieved though the keyword var.

Once some space is already reserved in memory, no need to use the keyword anymore - just referencing the variable through it’s name is good, as it works sort of like referencing the address in the memory where data will be (or is) stored.

So, in short, var is used to assign an address in memory for the variable you’re creating.

2 Likes

I figured it out. The instructions are misleading.
It’s just x = red. It looks like they fixed it as the sample is now showing up correctly for me now even after its reset.

This solution does not seem to work. I have tried quite a few times changing from red to yellow but it won’t accept as right answer.

Nevermind, I figured out what is was asking you to do.

3 Likes

Another reason for `var` is to help identify typos. So, in environments where Strict Mode can be enabled, this might give a warning or error:

`var wahh = 1`
`wahhhhhhh = wahh + 1`

–Scott.

1 Like

Hey @MakerCK_Studio,

You’ve created a new variable, rather than updating the variable’s value. Try resetting your code, then change `x = red` to `x = yellow`; no need to use the `var` key.

H

1 Like

Hi,só im having a problem maybe i didnt get the challange ( im a newbie) but It is to make the flag Go Blue and yellow, i did that( the va x = Blue and yellow) but the game is not reaponding.
Again, im a noobie
can Someone explain what is happening?