Scratch Lab #4

Name: Daniel Harris

Period: 7

Assignment: Lab #4

Lab Overview

This lab focused on using variables to store different values. For example, the variable could be set to contain information, such as whatever the user of the program gives, or it could be set to a number that could increase or decrease depending on the conditions and could affect things defined as numbers, such as position, or volume, or speed. In our lab, we experimented with changing variable using buttons clicked in the program. Click HERE for the full description.

My Solution 1 (Problem 1)

My first challenge was to create a program where a sprite forever switches between its costumes, and to add buttons that could be clicked to change how fast the costume changes. In the cat's script, I had the speed variable I made set to 0.5 to start, and inside a forever loop I told the cat to wait the variable "speed" number of seconds before changing costumes. I then made to other sprites called faster and slower , in which I put the blocks, "When this sprite is clicked" followed by "change speed by 0.01" for slower, and "change speed by -0.01" for faster, so the cat waited a longer or shorter amount of time before switching costumes.

Problem 1 Link

My Solution 2 (Problem 3)

The next challenge was to create a program that could calculate the distance between two points. I first made two sprites that were dots, and I made four variables to store their two x positions and the two y positions. I asked the four variable values and set the answers to the coordinates of the points. I made one finale variable called distance and I set it to the distance formula. I then set one of the sprites to say distance after the other variables have been assigned values.

Problem 3 Link

My Solution 3 (Problem 4)

The final challenge was to make a program with sprites dancing to music with buttons to control the volume, and have the police appear when the volume gets too loud. To make the sprites dance I made the sprites switch costumes every half second in a forever loop. For the buttons I started with a "when this sprite is clicked" and followed with a command to either increase or decrease the variable volume by ten. I also had a forever loop with the command to set the volume to the variable "volume" percent. I had another sprite that appears when the volume gets greater than 60 and stops all scripts.

Problem 4 Link

Questions

  1. Are variables in computer programming the same as variables in math class? Why or why not?
  2. When creating a variable, what are the two types of scope a variable can have? That is, what can it affect. (Think about your options as you make a variable)
  3. How many values can a variable store at one time?
  4. What will the following code snippet do? Explain why it doesn’t work as intended.
  5. Given the following code snippet, explain what is happening.