Unit 5 Test Review

Ace your homework & exams now with Quizwiz!

var myNumbers = [32, 64, 33, 0, 15, 26, 3] myNumbers[0]

32

What is stored in studentScores after running the program code? studentScores = [77, 32, 45, 92, 86] For Each item IN studentScores { IF ( item > 60 ) { item = item + 5 } ELSE { item = 0 } } [82, 0, 0, 97, 91] [5, 0, 0, 5, 5] [0, 37, 50, 0, 0] [77, 37, 50, 92, 86]

[82, 0, 0, 97, 91]

What is a list?

a collection of organized items

What is filter in a list?

create a subset of elements from the original list

What is a loop? (Not on study guide)

define and control behavior that repeats

How to read? var pixels [28,75,30,200,103,0 ] for (var i = 0; i < pixels.length; i + +) } pixels[i] = pixels[i] + 50; console.log(pixels);

pixels at index i, pixels at 0 is 28. 28 plus 50 is 78. Pixels at index 0 is updated to be 78. The next time through the loop, i is 1, so pixels at index 1 will be updated in the same way. Will happen for each item in the list.

What is traversal? (Not on study guide)

the process of accessing each item in a list one at a time

What is a index?

element in a list or string using numbers (slot number)

What will be displayed after this code is run? a = 0 Repeat 3 times a = a + 1 Display a a = a + 1 "1 2 3" "2 4 6" "1 3 6" "1 3 5"

"1 3 5"

What will be displayed after this code segment is run? Count = 0 Repeat until Count = 3 Count = Count + 1 Display "and" Display count "1 and 2 and 3" "and 1 and 2 and 3" "0 and 1 and 2" "and 0 and 1 and 2"

"and 1 and 2 and 3"

var myNumbers = [32, 64, 33, 0, 15, 26, 3] myNumbers[4]

15

Why is traversal with a for loop a good method for accessing and updating items in a lengthy list?

Because you want to process every item in the list in a similar way, you can use a loop to iterate through every item and take some action with it.

What are for loops?

Condenses the parts of a while loop into a shorter statement. Similar to the while loop, once the Boolean expression becomes false, the loop ends. (Counter loop; counts 0 to the number user types in) (repeats command as many times as user (we) needs) repeats a specific block of code a known number of times

What are iteration loops?

a repetitive portion of an algorithm that repeats a specific number of times or until a given condition is met. (repeats until it holds true)

How are loops examples of iteration?

a repetitive portion of an algorithm which repeats a specified number of times or until a given condition is met.

What is going on? // Location button is clicked onEvent ("locationButton", "click", function) ( ) { for (var i = 0; i < 20; i++;) { setProperty("icon" + i, "x", randomNumber (0, 300) ) ; setProperty("icon" + i, "y", randomNumber (0, 300) ) ; } playSound ("sound: // category__bell/choose__background.mp3") ; } ) ;

on the event that the location button is clicked a sound will play. A for loop is used. i starts at 0. Icon starts at 0. There are 20 icons. It will go to 20. Set property on icon plus i. Icon 0 goes to the bottom of the loop, back to the top. i equals i plus 1. Icon 1, icon 2, all the way up to icon 20. Changes the x, the x value to 0 to 300. set property for y. set property on icon plus i. changes the y, the y value to 0 to 300.

var myNumbers = [32, 64, 33, 0, 15, 26, 3] myNumbers[1]

64

var myNumbers = [32, 64, 33, 0, 15, 26, 3] myNumbers[3]

0

When breaking a problem down, you often encounter elements that you want to use repeatedly in your code. Sometimes it's appropriate to write a new function; at other times it's appropriate to write a loop. There is no hard-and-fast rule as to which is better, but what do you think? What kinds of circumstances would lead you to writing a function versus using a loop?

I think both are equally important. Functions allow for more variability, but loops make things faster. You may want to use functions instead of loops when you have one small part of the function, such as an angle, that you want to alter each time.

What are while loops?

Uses a boolean condition to repeatedly run a block of code. If it is true it runs the block of code contained within it. This process of checking the condition and running the block of code is repeated as long as the Boolean condition remains true. Once the Boolean expression becomes false it will stop. (runs a specific number of times by using a variable ) repeats a section of code an unknown number of times until a (specific) condition is met

What is append in a list?

adds an item to a list

What is a element?

an individual value in a list that is assigned a unique index

What is the list? var lunchFood = ["nachos", "pizza", "soup", "stir fry"];

lunchFood

What are infinite loops?

occurs when the ending condition will never evaluate to true. occurs when a condition always evaluates to true.

What is reduce in a list?

reduce the list down to a single element, for example: the smallest number in the list

What is iteration? (added)

repetition of a process or procedure (repeat)

What is the list? var scores = [3, 5, 10, 7];

scores


Related study sets

Geological Time Chapter 4 Section 3 / 4 Radioactive Dating / Geologic Time Scale

View Set

CH 20 & 21 Great Depression and the New Deal

View Set

Chapter 4. Nursing Process: Diagnosis

View Set

AP Euro Fall Semester Comprehension Practice Test

View Set

URSP 391 final: brand equity, sustainability assessment & reporting

View Set