Lab 2 Write Up

Name: Zak "The Legend" Singh

Period: 7

Assignment:Scratch Lab #4

Lab Overview

Click HERE for Lab instructions.

Problem 1

In this lab I had to create a sprite that would change costumes periodically, but also have buttons to increase and decrease the speed of it.

Problem 2

For problem #2, we had to make a program that would ask for information from you, store it, then have a conversation with another sprite that included all the information you entered.

Problem 3

For problem #3, I wrote a program that would allow you to enter the coordinates of two points, then automatically calculate the distance between them for you.

My Solution

Problem 1 Solution

For problem #1, I made the speed into a variable, and had each button either subtract or add to the variable. Then, the dancing sprite would use the speed variable's value for the waiting time between changing costumes.

Problem 2 Solution

For problem #2, I stored all of the info (name, grade, etc) as individual variables. After you finished entering your info, the sprite sent out a broadcast to the other one to show itself and start talking. The sprite then would ask "what was his name?" etc and broadcast a message for the other sprite to respond to. The other sprite would say the corresponding variable.

Problem 3 Solution

For problem #3, I stored the x and y coordinates for each point individually, then entered them into the formula in their correct positions.

Paired Programming

Problem 1

Problem 2

Problem 3

Questions

  1. Are variables in computer programming the same as variables in math class? Why or why not?
    • Sometimes, because they represent a number that is unknown. However, in programming you can do things like x=x*2 or x=x+5, which you cannot do in math.
  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)
    • A variable can either only effect the sprite it is created for or all sprites in the program.
  3. How many values can a variable store at one time?
    • A variable can only store one value at a time.
  4. What will the following code snippet do? Explain why it doesn’t work as intended.
    • The code tries to set the values to eachother, but it actually would make them the same because value1 becomes value2 then value2 becomes value1 in that order, so everything equals value 1.
  5. Given the following code snippet, explain what is happening.
    • When the sprite is clicked, then the "temp" variable is set to itself. First temp becomes value 1, then value 1 becomes value 2, then value 2 becomes temp, so temp becomes temp.