# Functions with return values

#1

My students are working on “functions with return values” (lesson 16) now. I really like the “constrain” function but it is pretty tricky for students. I am trying to think of other whole-class practice we could do together. Right now I am thinking of doing a function called canRide which returns true if a kid meets the parameters for a hypothetical amusement park ride (something like, if the age is greater than 8 and height is greater than 4ft, return true, else return false).

Then use they canRide inside an if else statement to show a picture of a happy kid if they can ride the ride, else, show a picture of a sad kid. I know I will have some students who will push back on if they really need a return and why they wouldn’t just make the pictures show up in the canRide function… but it is at least something to start with.

I am wondering what other ideas people have for practice with returns!

Thanks!
KT

#2

When I discussed this I told students to think about how the highway has a minimum of 45 mph and a maximum of 60 mph. I told them to pretend they had a car that would force the speed up to 45 if the driver drove less than 45 mph. If the driver went over 60, it would slow the car down to 60. Any speed between 45 and 60 would be stay as is.

The park ride is good but you will need a high input. Some rides do have a height maximum (not more than 76" say) so it would work for that.

I also had them look at the website below and remove the constrain toward the bottom (on this website constrain is already a function in the library.)

https://p5js.org/examples/input-constrain.html

Unit 5 -Lesson 16 #6-8