Slider code in U6L13

Why is the var speed=10 needed at the top? And why can’t you just get the slider value?


Can you post a link to the lesson or project you are referring to? I can’t find any of the projects in the 2020 or 2021 curriculum for unit 6 lesson 13 that have a speed variable or a slider … but I could have missed something in quickly looking it over. That is the lesson on accelerometers if I am not mistaken.



[](Link to level)

I can’t seem to get the link to work

OK… I see now.

This is unit 6, lesson 6, level 12/13. I was looking at lesson 13 rather than lesson 6.

The challenge of level 13 is to do what you suggest. Create a slider that you can use to access the speed (rather than having a “speed” hard coded into the program as it is in level 12).

Before you create the slider, you would hard code the speed. Then, after creating the slider, the program should “get” the speed from the slider.

Does that answer your question? If not, let us know and we can try to clarify.



I do understand, but the hard code for the speed has to remain at the top for it to work. I am trying understand why that is necessary. In my mind I should just be able to get the value of the slider, which is what I did at first. It returned an error that value wasn’t measurable. I tried adjusting the slider min and max, but that didn’t make a difference. The only way it works if if I leave the hard code of var speed=10 at the top. Why do I need this if what I really want is the slider value?

PS - apologies for not getting the lesson tagging correct.

No worries on the tagging … there’s a lot to unpack there…

You shouldn’t have to hard code the exact speed, but you do need to declare the speed variable. (var speed;)

Then, the slider should be able to update it. A lot of times, you will hard code some number (zero is common). It depends on your project. Do you want it to have a speed to start with? But that usually comes intuitively depending on the project you are making.

Here’s an example that works with just declaring the variable, but not setting it to a number.


1 Like

That was what I was missing. I see that you didn’t give a value to the speed declaration.

I had tried putting in the get slider value in there, and it didn’t work.

var speed = getProperty(“slider1”, “value”);

Now I understand that it doesn’t need to have a value to be declared. I thought it did.

Thank you so much!!