Help! Need code to display color


#1

What is the code for color? The example does not show where to actually type in the color. I am so confused with this and am trying to teach myself. I wish there was a video to help with coding the Circuit Playground boards.


#2

Not sure what bubble you are on but you can always see the solutions to each bubble by clicking on “Example Solution” on the Teacher panel.


#3

The solution is not there for the color. It just says “color”.

This is for Lesson 12 Puzzle 13.


#4

Patti,

This level is confusing - it’s using parameters that you pass into the function to affect the code. color used as the parameter (in the parenthesis after the function) which is user defined, then the function takes the color and applies the value later in the code whenever the word color is used. So, like the last sentence of the example, you can call the function setLEDsColor with a parameter of “blue” and later in the code, all instances of color in the function will be assigned to “blue”.

Hope that helps!
Brad


#5

Yes that does make sense. I looked at the example and “plugged” in red. Is this correct?

function setLedsColor(red) {

for (var i = red; i < colorLeds.length; i++) {

colorLeds[i].color(color);

}

}

Thank you for your help!!


#6

Patti,

You are close!

When you are creating the function, you want to have variable names that are going to be filled in… so instead of “red”, you’ll use “color” and then when you call the function - “red” will be typed into the parentheses and everywhere in the code that it says color it will be “red”. In your code, where “color” appears, it will be replaced with “red” when you call the function.

In your for loop, the header has three parts, 1.) a variable created and assigned, then 2.) checked to see if the value is “true” and then 3.)increasing. Your code needs to have var i = 0; assigning the variable i a value of 0 (or as Josh says in the video, variable i “gets” 0). Then i is checked to see if the condition is true, which in your code is the length of the colorLeds array (which is correct). Then I increases to go through each index of the array. In the body of the for loop you are increasing the index location of colorLeds with the variable I and using the dot notation of .color to change to the (color) which is a variable in your code, but when the function is called is the color the user has used as the parameter in the setLedsColor function.

Hope that helps!
Brad