Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Unit 4 Variables, Conditions, and Functions, Exams of Advanced Education

Unit 4 Variables, Conditions, and Functions

Typology: Exams

2024/2025

Available from 10/25/2024

cate-mentor
cate-mentor 🇺🇸

1.8K documents

1 / 8

Toggle sidebar

Often downloaded together


Related documents


Partial preview of the text

Download Unit 4 Variables, Conditions, and Functions and more Exams Advanced Education in PDF only on Docsity! Unit 4 Variables, Conditions, and Functions What will the value of score be at the end of the program? Note: <- is used to represent a left facing arrow var score score <- 3 score <- score + 1 score <- "The score is: " + score - The score is: 4 Explain in your own words the process of creating and updating a variable. How does the Counter Pattern with Event work? - Creating a variable and updating a variable is put on the top to allow for a call back to the variable in the program. Variables allow for changes in the program and are important for this reason. The Counter Pattern Event works as an event program so the initial sequential program gets disrupted and a change in an event happens. How does a baggy represent a variable? - The baggy represents a variable because it is assigned a value of 3. Variables are assigned values. Predict the information that is being stored in variables for the thermostat app? - The information that is being stored in the temperature in Fahrenheit. How does the Fahrenheit app work? - The initial temperature is set to 70. When the down button is clicked it will subtract the temperature at the given time by 2. Then that number will be applied to add an F. The numbers will actually show on screen and play a sound. Vice versa. How does math.round work? - Math.Round rounds a long decimal number to the nearest tenth. How does getText() work? - This allows for a callback to an input that the user put in. What can be stored in a variable? - Variables can store anything that is important to hold or to be called back upon. Why is using a meaningful name for a variable important? - A meaningful variable is important for the coder to remember what the variable entails. What is a variable? - a reference to a value or expression that can be used repeatedly throughout a program or a placeholder for a piece of info that can change Which of the following COULD NOT possibly be the output? a <- RANDOM(1,10) b <- RANDOM(10,20) DISPLAY(a) DISPLAY(a) DISPLAY(b) DISPLAY(b) - 10 5 10 5 Can a computer evaluate an expression to something between true and false? Can you write an expression to deal with a "maybe" answer? - Yes the computer can evaluate an expression to something between true and false. A computer can't deal with a maybe answer. Chocolate cookies < vanilla cookies This will give an expression to deal with a "maybe" answer for humans because somebody might have a different opinion. When creating an if-else-if statement you should always make your first condition the most specific. Write a short paragraph responding to the questions below. - The most specific case first means the most selective part of the if-else-if statement or the case that will help determine the cases of the others. It's important to put the most specific case first because the computer runs code from top to bottom and if the most selective part is anywhere but the top then this will create massive bugs score <- 4 Create your variables outside any function or onEvent()bocks. How does a Global variable work? - Permanent. Can be used anywhere in your code. How is a Global variable created? - var used outside an onEvent() How does a Local variable work? - Temporary. Can be used only in the part of the code where it was created, like inside an onEvent(). Deleted once the onEvent() is done running. How is a Local Variable created? - var used inside an onEvent() What is the biggest issue with local variables? - accidentally using var inside of an onEvent() or function. Imagine you want to make a decision about what to wear to an event. Name two pieces of information you'd want. How would you use them in your decision? - The occasion The weather What can info be stored as? - Numbers, Strings, Booleans What are numbers? - Made of digits 0 through 9 What are strings? - Made of any characters Inside double quotes What are booleans? - Value that is true or false What info do you need to know going to the movies? - Showtime, The length of the drive, The length of the movie What info do I need to know about score* my lives is greater than 10? - Score and Lives What are logical operators? - Boolean values are a type of information, so they can also be evaluated in a Boolean expression using logical operators. What are the Logical Operator functions? - && AND || OR ! NOT What do comparison operators do? - indicate a Boolean expression What is the difference between a boolean value and boolean expression? - Boolean values are true or false and boolean expressions evaluates to either true or false What is a syntax error? - Your code doesn't follow the rules of the programming language What are examples of syntax errors? - Writing a variable name in quotes Using a variable that doesn't exist How to debug syntax errors? - Check warnings and errors What is a logic error? - Your code follows the rules of the programming language but doesn't do what you intend What are examples of logic errors? - Writing if-else-if statements in the wrong order Updating the property of the wrong element How to debug logic errors? - Test your code What are the benefits of writing a song in Style 2? - Can save time repeating lyrics and can be easily repeatable What is a function? - a named group of programming instructions. Also referred to as a "procedure". What is a function call? - a command that executes the code within a function What does "when" refer to? - Means there is an onEvent to respond to user input. The app does something "when" the user clicks. What does "if" refer to? - Means there is a conditional statement that decides what pieces of code to run. The app does something "if" a boolean expression evaluates to true. What is the difference between an if-statement, an if-else statement, and an if-else-if statement? How are they similar? - They are essentially the same thing but get more complicated as it goes on. An if- statement is causes something to happen if another happens. The else adds on to another contingency which will cause another thing to happen. The else if is a continuation of the if statement and is a more specific contingency. var x = 2; var y = 3; x = y; y = 5; x = 10; y = 4; console.log(x); - 10 var x = 5; x = x+1; x = x+4; x = x+9; console.log(x); - 19