Scratch Lab 4

Name: Shreya Raj

Period: 7

Assignment: Lab #4

Lab 4 Overview

This Scratch Lab focused on using variables. The lab made students really understand variables by experimenting with variables and making students create new variables for their sprites. By creating variables you were asked to complete specific problems to help further understanding. For example using variables in animations to control different aspects of the animation. The variable could control volume, speed, or it could be even more interactive with the person watching the animation by asking questions to the viewer. Click HERE to get to the lab instructions.

My Solution Problem Number 1

For this problem you were told to create a simple animation with the ability to change the speed of the animation by clicking 2 different sprites. This involved creating a variable called speed. My solution involved a simple animation of a costume change for my main sprite and I included two other sprites that look like buttons to help change the speed variable. I set the speed variable to 0.2 seconds, and added the “when this sprite clicked” command to my button sprites to control the speed. For the “faster” button, I gave the command that when this sprite was clicked the variable, speed, would change by -0.2 seconds. For the “slower” button, I gave the command that when this sprite was clicked then the variable, speed, would change by 0.2 seconds. This would cause the speed variable to increase by 0.2 every time the “slower” button sprite was clicked.

My Project Link

My Solution Problem Number 2

For this problem you were told to have a sprite have a conversation with you (the viewer) and after a series of questions, that sprite would talk to another sprite about the answers you gave. This problem required creating four different variables and using another variable provided by scratch called answer. I created a name variable and then I would command the sprite to ask a question like “What’s your name?”, and set the name variable to the answer. For different questions about food, grade, and activity I created new variables. Then I set the those variables about the questions to the variable of the viewers answer (use the answer variable, for example set the food variable to the answer variable). By doing this, when the sprite had to talk to the other sprite about the dialogue it was easy, as I used the broadcast message command and made the sprite say the answer from the specific variable.

My Project Link

My Solution Problem Number 4

For this problem you had to create a party with at least three sprites dancing and when the volume increased, at a certain point, the police should have arrived and the sprites should have ran away. To solve this problem my code involved a simple costume change for each of the dancing sprites. Then I created another sprite to increase the volume when it was clicked, so I used the volume variable. In the button code where the sprite changes the volume, I set the volume to 20. But then I added a command that changed the volume variable, so it would be whenever this sprite was clicked the volume would increase by 5. After doing this, I needed to get the police, so I used an if then conditional statement and an operator command. That statement was that if the volume variable was greater than 70 then to broadcast message 1. Message 1 would then sound a police siren and show the police and have the dancing sprites run away.

My Project Link

Questions

  1. Are variables in computer programming the same as variables in math class? Why or why not?
      No because variables can change where as in math class variables usually have a specific value given to it.
  2. When creating a variable, what are the two types of scope a variable can have? That is, what can it affect?
      It can affect either one sprite or all sprites.
  3. How many values can a variable store at one time?
      Variables can hold only one value at a time.
  4. What does the following snippet do? Explain why it doesn't work as intended.
      It's intention is to have the values set to each other but it creates a paradox as the value_1 and the value_2 is always changing.
  5. Given the following code snippet, explain what is happening.
      It is creating a loop between all the different variables and it can not operate without knowing a set value.
  6. Click HERE to return to homepage.