The aim of this puzzle: Create and print out the value of a new variable that stores the current year.
Walkthrough of the solution: This puzzle starts out with two lines: var lastYear = 2017
and print(lastYear)
. The first line starts with var lastYear
which means: create a new variable and call it lastYear
. You can think of a variable like an empty container with a label on it. The label doesn’t change, but you can put whatever you want inside of the container. To put something inside of the container, you use =
. In this case, the code is going to put the number 2017
inside of the lastYear
variable.
The second line uses a function called print()
. This will take whatever you put in its parentheses and try to write text on the screen as a string. If you print a string, you will see just see the string. If you print a number, you’ll get the number. But if you print a variable, you will see the value stored inside that variable – not the name of the variable. That’s why print(lastYear)
writes 2017
to the screen.
Your goal is to add to this code to create a variable that stores this year and prints that to the screen. You can almost copy the first two lines, changing the name of variable and the value it’s storing. You can call your new variable something like thisYear
and then use =
to put the current year inside of it. Then you can use print()
to print out the value you just stored inside of thisYear
.
Sample code solution:
(Tap below to reveal)
var lastYear = 2017;
print(lastYear);
var thisYear = 2018;
print(thisYear);
JavaScript Concepts: Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: print()