The aim of this puzzle: Reveal the hidden image by adjusting all boxes with a 0 blue value to be over 200.
Walkthrough of the solution: The main goal of Blue Filter is to draw out an “enhanced” version of the boxes stored in anArrayOfObjects
; in this case, enhanced means bringing out the blue-ness of some of the boxes. There are two main parts of your code:
First, find a way to draw a box for each object stored in the array called anArrayOfObjects. You can’t see exactly what’s inside the array, but from the name, you can imagine it’s a list of RGB objects that look something like:
{
red: 123,
green: 24,
blue: 0
}
Using a for...of
loop and drawBox()
, you should be able to see what’s inside of the array.
Once you’ve done that, you want to find a way to check if a box has zero in its blue component, and then bump it way up so it’s really blue (something over 200, we’ll use 255). The way you do that is with an if statement. You want to check if element.blue === 0
and if it is, set element.blue = 255
Remember that ===
is checking if two things are equal and =
is storing the right side into the left side.
Now you have your two main parts, and you just need to know how to combine them. What you want is to put your if statement check inside of the for...of
loop because you need to check every object. Then, you need to decide if it should go before or after the drawBox()
command. You want to do the check and adjustment to the blue value before you draw, otherwise how will you see what you’ve changed? One important thing to remember is that drawBox()
can only draw colors or RGB objects (like the individual objects listed in the array).
Review cards:
If you’re looking to practice on a few previous cards to help you with Blue Filter, these four should help you – especially Basic Image Decoder and Going Green. When you solve these, make sure you understand what each part of the code does and when the order matters.
- Ukraine to Haiti (assignment)
- String Looping (
for...of
) -
Image Decoder (
for...of
with nested if) - Going Green (if with member expression in condition)
Sample code solution:
(Tap below to reveal)
This is the final card in this course (woohoo!) — to test your knowledge there is no sample solution code
JavaScript Concepts: Binary Expression (=), Code Block (for loop, if statement), Calling Functions, Conditionals (===), Identifiers, Loops, Member Expression, Variable Declaration
Grasshopper Concepts: drawBox()