Winter Is Coming explainer

The aim of this puzzle: Take 10 seeds away from the Ant and give them to the Grasshopper.

Walkthrough of the solution: The first 3 lines of code create the 3 variables: ant who has 40 seeds, grasshopper who has 0 seeds, and gift which has 10 seeds. The ant is paying for the gift, so the value of ant should go down by 10. The -= operator is used to decrease a variable’s value. The grasshopper is receiving the gift, so it gets the gift added to its value. Using grasshopper += gift will add the gift value (10) to grasshopper (0 --> 10).

Sample code solution:
(Tap below to reveal)

let ant = 40;
let grasshopper = 0;
let gift = 10;
ant -= gift;
grasshopper += gift;
print('The Ant has ' + ant + ' seeds, and the Grasshopper has '
      + grasshopper + ' seeds');

JavaScript Concepts: Assignment Operators (+=, -=), Binary Expression (+ concatenation)

Grasshopper Concepts: print()

1 Like

I tried to do it, but I can’t. Please help. Thanks!

I did what it said but it still doesn’t work…help please.

Could you post a screenshot of your code?

–Frankie

I figured out, I was using the code without realizing it.


I can not figure out what’s wrong with is
Update I kept typing gift not selecting gift I’m good now

5 Likes


Gift is a var, not a string

4 Likes

Start tutorial please

I need help too

(you can fullscreen it if you put your curser on the picture and go to the lower right hand corner, there will be a full screen button, it looks like arrows that are facing the opposite side (Diagonally)and if you click it, you will be in full screen mode) (If you didn’t know)

so what the difference betwen increment & decrement operator with addition & subtraction assignment ?

@grasshopperexplainer

Solution:

Thanks. It was so easy that I got confused xD

If you guys are stuck, take a look at the concept example ‘Using += and -= operators’ and practice them on your own. If you guys still stuck, then mention my name @Pummarin_The_gamer and describe your problem, plus a screenshot.

i keep trying but i cant either

Hi, I need help too. Please

If you send a screenshot, I would be more than happy to try to help you.

Screenshot 2020-12-17 at 2.19.20 PM

Instead of ant -=1; and grasshopper +=1;, try using the gift variable. It should look like this:

let ant = 40;
let grasshopper = 0;
let gift = 10;
ant -= gift;
grasshopper += gift;

Hope this helps! :hugs: