Name: Shreya Raj
Assignment: Lab #7
This week’s lab was all about blocks. The purpose of the lab was to learn how to create blocks and the to understand the different parameters blocks can obtain. To really understand blocks we had to do a pair programming problem and do two individual problems. After finishing this lab it was evident how useful blocks are to make your code a lot more organized and elegant. Click HERE to get to the lab instructions.
This problem was the area of a rectangle problem. My solution for this problem was to create 3 variables (width, length area), created a block called “area”, and use an existing variable on scratch called “answer”. Then I set my length and width variables to answer and set my area block to width and length. My block “area” had two parameters and I defined the block with the parameters. What I mean by that is for defining the area block, I set my width to the first parameter and the length to the second parameter of the area block. Under defining my area block, I also defined the area variable to an operator which multiplied the two parameters. Then to provide the side length of a square with the same area; I just had programmed my sprite to say the square root of the area variable. Then to provide the side length of an equilateral triangle with the same area; I just programmed my sprite to say the square root of the area divided by 2.
This problem was the feet to inches or miles. My solution for this problem was quite simple. I used the answer variable and a block I created with one parameter to solve this problem. First I had the sprite ask “How many feet?”, then I set the block to the answer. Then the rest of my solution was under the define block. I used a conditional if-then-else statement to solve the problem. The first part of the if-then-else statement stated that if the foot (foot was the parameter) was greater than 5280 then to divide the foot by 5280. Else if the foot was not greater than 5820 then I would have had the sprite multiple the foot by 12 thus converting the feet to inches.