NEW
Font size
WorksheetsCode.org Unit 3 Functions
Total questions: 35
Worksheet time: 32mins
When programmers work together, what is an example of an abstraction in programming that can promote collaboration?
Team members can rely on one another to explain their code.
Programmers can write functions without needing ot know what they do or how they should work.
Programmers can use functions created by others, relying on the functionality without knowing details of how the function works
In order for programmers to work together, they must be in the same room.
Why are parameters useful when programming?
Parameters change the order of operations within a function.
Parameters help teams of programmers because they define the problems they are trying to solve.
Parameters allow for more flexible, generalized behaviors in functions.
Parameters determine the number of times a function will run.
Look at the following code. Which line should the following comment go? "Shake back and forth"
Line 5
Line 11
Line 14
Line 17
Line 19
Why are functions useful?
They allow us to organize our code
They make our code easier to read
They allow us to create commands that we can use whenever
All of these
Which function would you expect to call if you were trying to have the user move a sprite?
drawBackground()
moveSprite()
changeScore()
gameOver()
Which sprite property replaced the sprite.x = sprite.x + 1
sprite.velocityX
sprite.velocityY
sprite.y
A note in the source code of a computer program that helps explain the code to people who read it:
Comment
Whitespace
CSS
HTML Tag
When calling sprite.IsTouching(target) and you increase the score, why does the score go up so high?
Because the draw() function is a loop and the two sprites are touching many times.
What? no my score only goes up once. The sprites only touch once.
The IDE knows that I don't want to increase the score just by one and gives me a larger number because it thinks it's better to use larger numbers.
Because the sprite don't actually touch once I set sprite.visible = false.
What is the difference between sprite.visible being false and using sprite.destroy ( )?
nothing, they're both the same
sprite.destroy( ) requires that you re-create the sprite
sprite.visible = false will require that you re-create the sprite
because you can no longer see the sprite, then it no longer exists
Give an example of a nested if-condition
if(keyDown(up) and keyDown(left)) then sprite.y = sprite.y + 5;
if (keyDown(up)) then sprite.y = sprite.y + 5;
if (keyDown(up) or keyDown(left)) then sprite.y = sprite.y + 5;
if (keyDown(up)) then if(sprite.y > 400) then sprite.y = 0;
In the draw loop, if you call the text function before the drawSprites and/or background function, what happens?
You won't be able to see your text because the sprites and background will be drawn on top of the text.
You will be able to see your text because Game Lab knows you want to see the text.
You won't be able to see your sprites or background because order doesn't matter.
You will be able to see your text because the sprites and the background will be drawn after the text.
What code do we add to make the elephant push the hippo off the screen?
Predict what will show up on console.log
true true true
true false false
false false false
true false true
What happens in this code?
nothing is shown, there are no sprites
the background is white and we can't see anything because the textsize is 0;
the background is white, the counter increases in size as the counter increase.
the background is white, and we see a number that goes up but the textsize stays the same.
What happens if you don't call background in your draw loop and your sprite has movement?
nothing, animation is fine.
the sprites are drawn on top of each other to simulate movement, the older drawings don't get erased.
you don't need to call background because you don't have one.
you can just use sprite.move( ) so there's no need for the function background( )
What is a good name for the function?
score
totalPoints
backgroundChanges
angryBackground
Understanding the problem when it was assigned.
Try
Reflect
Define
Prepare
Examine results. Ask yourself: "What needs to change?"
Define
Prepare
Try
Reflect
The work done (possibly by a computer) to turn input into output
Input
Storage
Output
Process
Elements that make a computer a computer
Input
Output
Process
Storage
All of the above
A precise sequence of instructions for processes that can be executed by a computer
Input
Algorithim
Output
Define
Actually run the plan. Observe any results.
Define
Prepare
Try
Reflect
Where do functions go in a Javascript program on Code.org
At the top
Below the sprites
in the draw loop
Below the draw loop
What does this code do?
Resets the position of the coin sprite
Adds points to the score
Increases the velocity
Sets a random Y value
If I were to put this code in a function, what would I call it?
score
upDownMotion
move
collectCoin
