Name: Colin Yang

Period: 7

Assignment: Lab #4

Lab Overview Problem #1

This lab asked us to create one main sprite that would continuously change costumes. On the left side would be a button that makes the sprite change costumes faster, and on the right side would be a button that makes the sprite change costumes slower.

My Solution

For my solution, I created a variable and set it to 0. When the button on the left was clicked, I had the variable would change speed by -0.5, while the button on the right was clicked, The variable would change speed by +0.5. The main sprite would wait the "speed" secs and switch to the next costume.

My Project Link

Lab Overview Problem #2

This lab asked us to make a sprite that would ask the user multiple questions and then introduce the user to another sprite using the given information.

My Solution

For my solution, the first sprite would ask a question and set a new variable to the anser. After waiting a second, it would ask another question and the procedure would repeat until all four questions have been asked. Then, it would broadcast a message that siganls another sprite to appear. The new sprite would ask a question and wait two seconds four times, while the first sprite would answer the questions and wait two seconds.

My Project Link

Lab Overview Problem #3

This lab asked us to make a program that would find the distance between two ordered pairs.

My Solution

For my solution, the sprite would ask the user for the two ordered pairs. Each answer that is given is set as a new variable and after waiting a brief moment, the sprite would plug the answers into the distance formula and project the answer on the screen.

My Project Link

Questions

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

The idea of using variables are the same as in math class, as it sets a certain number as the variable (let x=1738 for example). The variable can then be placed into an equation/script for the sprite to follow. However, the value of the variable could be set as a certain word for the sprite to react to.

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)

The variable can be set to a certain number that the user desires, and it can also increase/decrease by a certain number. In addition, the user is given the option to either show or hide the variable from the screen. Once the variable is created it can be placed into certain blocks such as motion, looks, and operators.

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

Scratch gives you the ability to create as many variables as the user wants.

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

The code snippet would be on an infinite loop that changes each other's value continuously. If the user wants to do this, he/she should have two separate sprites that switch the value 1 to value 2 when clicked, and another that switches the value 2 to value 1 when clicked.

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

The code snippet simply switches the value of the three variables to each other. As long as the user has previously indicated what each variable is, temp should be set to value 1, value 1 to value 2, and value 2 to temp. For example, if temp is 1, value 1 is 2, and value 2 is 3, temp should become 2, value 1 should be 3, and value 2 should be 1 if the sprite is clicked.