Lab #4 Write Up

Name: Kelly Yokoi

Period: 7

Assignment: Lab #4

Lab Overview

In scratch lab #4 I learned about variables and how to use them in scratch. A variable is a changeable value that can equate to a number or some text. There are two types of variables: local(can be used by one sprite) and global(can be used by all sprites).

My Solution Problem #1

For Problem #1 I created three sprites: two buttons and a character with multiple costumes. I also made a variable named "speed." For the character I set "speed" to 0.5 and in a forever loop had that be the number of seconds in between each costume change. For the faster button I had it set "speed" to "speed-0.1" so that the time between each costume change would be shorter and the animation would look faster. For the slower button I had it set "speed" to "speed+0.1" so the time between each costume change would be longer and the animation would look slower.

Problem #1

My Solution Problem #2

For problem #2 I had a sprite ask the 4 questions and set the answer that the user inputs as a variable. When all the questions were answered I had the question sprite broadcast a message to another sprite to make it appear on the screen. The question sprite would then tell the other sprite about the user according to the answers they input.

Problem #2

My Solution Problem #3

For problem #3 I created 4 variables named x1, y1, x2, y2 just like the variables in the distance formula. I had the sprite ask the user what the variables are as they represent the coordinates they would like to find the distance between. I had each variable equal the user's answers.Then I had the sprite calculate and say the distance by putting a square root operator with the part of the distance formula that's inside the square root ((x2-x1)(x2-x1)+(y2-y1)(y2-y1))in a speech bubble block.

Problem #3

Questions

  1. Question #1

    Are variables in computer programming the same as variables in math class? Why or why not?

    • Yes because they both have a value; they equal something. Mathematical variables are symbols that represent numbers and in programming they are symbols that represent values.
  2. Question #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)

    • It can affect either one sprite (local) or it can affect all the sprites (global).
  3. Question #3

  4. How many values can a variable store at one time?

  5. Question #4

  6. What will the following code snippet do? Explain why it doesn’t work as intended.

  7. Question #5

  8. Given the following code snippet, explain what is happening.

Click HERE to return to homepage.