7. Exercises 3
-
Write a function
at-most-250
that takes in a number and puts out the same number, or 250 if the number is larger than 250. -
Write a function
small-0
that takes in two numbers and gives out the distance to zero of the number that is closest to zero on the number line. It should work with negative numbers as well. -
Write a function
stuck-50-150
that takes in a number x and gives out x. Except if x is below 50, give an answer of 50. Also if x is more than 150, give an answer of 150. -
random-a
: Write a function that gives a random number between -50 and 50. -
random-b
: Write a function that gives a random even number 0-200. -
dice
: Write a function that gives the total from randomly rolling two six sided dice. -
rstar
: Write a function that makes a star with a random side length. -
dstar
: Write a function that makes two stars next to each other, one should have a random side length and the other should have sides that are twice as long. (Note: make sure to write and test your non-random function first!) -
Challenge: make a star with a random number of sides. For the third number, the “step”, try
(remainder 31 sides)
. You will want a helper function that knows the number of sides.