Blue 222 Explainer


#1

The aim of this puzzle: Edit the properties of an object to create the color blue.
Walkthrough of the solution: This puzzle involves editing the properties of an object. An object is one of the fundamental data types in programming, and is used to store multiple pieces of data in 1 single variable.

For example, rather than having 3 separate variables:

var name = 'Josie';
var species = 'dog';
var age = 0.8;

1 single object could hold all of this related information:

var pet = {
  name: 'Josie',
  species: 'dog'
  age: 0.8
}

To access the data inside of an object, use dot notation: pet.name. (There is also bracket notation, which looks like pet['name'], but this is not used in the Grasshopper app, and generally dot notation is preferred.)

In this puzzle, we will edit the values of an object that has the properties red, green, and blue, and then pass this object into the drawBox() function. This will tell the function how red, green, and blue the box it draws should be, on a scale of 0 - 255.

To solve the puzzle, set the red and green properties to 0, and the blue property to 255. This will draw a blue box.

Sample code solution:
(Tap below to reveal)

var customBlue = {
    red: 0,
    green: 0,
    blue: 222
};
drawBox(customBlue);

JavaScript Concepts: Calling Functions, Identifiers, Variable Declaration, Data Structures (object), Code Block (object)
Grasshopper Concepts: drawBox()


listed #2