Scratch Lab #7
Name: Robby Rowell
Period: 7
Assignment: Scratch Lab #7
Lab Overview
This lab required us to make and define blocks. For problem 1, we had to make a block that calculates the distance between two points. For problem 2, we had to make block that converts feet into inches and feet into miles.
HERE.
My Solution
My solution to problem 1 was to create a block that takes four parameters, x1, x2, y1, and y2. I made four variables, also called x1, x2, y1, and y2 and set them as the parameters. I then had the sprite ask for four cordinates, and set the variables as the answers to the questions. The block I made took the four parameters and used the distance formula to calculate the fifth variable, distance. For the second problem, I created two if statements with different blocks for each outcome. The blocks would take the answer to the question asked and convert it to feet or miles by either dividing by 5280 or multiplying by 12.
My Project Link
Questions
- What are two advantages to using blocks for code repetition?
You can use the same code repeatedly to perform the same actions and it is easier to find and fix mistakes in your code.
- What are parameters?
Parameters are the different options that can be added to your blocks, such as numbers or boolean inputs.
- Give an example of a formula that takes at least one parameter.
An example of a formula with a parameter would be the distance formula, which takes four parameters (x1, x2, y1, y2).
- Give an example of a situation where no parameters are needed
An example of a situation where no parameters are needed could be when you are defining a simple recurring action in order to simplify your code.
- Explain what you think the following program does? How do blocks make this easier to understand? Explain what you would expect within each block.
This program is defining a block that runs until a list is in a certain order or until a name is given that makes the task complete variable true. Inside the "get name" block, you would expect a question that asks for a name and setting the name as a variable. The "insert into list" block would put the variable into a list, then the next block would reorder the list. The "continue" block would check to see if new list makes the original variable true.