Computer Science

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

When and If

"when": Means there is an onEvent to respond to user input. The app does something "when" the user clicks. "if": 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.

different combinations of boolean statements

( __ OR __) OR (__AND__)

DON'T GET TRICKED BY THIS THE FORMAT HAS TO BE LIKE THIS:

(day=="thursday || day="tuesday") NOT (day=="thursday ||"tuesday")

money==40 && age>40

= means assigning the variable Don't get confused with == which actually means equal

((day==tuesday) ||(day==thursday))||(age>12 && age<21)

One condition if it is tuesday or thursday free admission Other condition have to be older than 12 AND less than 21 to get free admission Combine these two with an OR statement because either of them can be true to get free admission ELSE: they will not get free admission. USE PARENTHESIS: it will evaluate each boolean separately first

if(score>15){ Lemon width=60 Else If (score>10) Lemon width=100 Else if(score>5) lemon width=120 Else{ Lemon width=140

Greater than 10 is most specific, because greater than 5 is also greater than 10. (you can do multiple else-if statements)

logical operator

NOT, AND, OR evaluates to a Boolean value. &&: AND. | |: OR. !: NOT

counterpattern with event

On event press score button score=score+1 stats="Score:" + score Set text(score label, stats)

Var age=25 If age>=17{ write(you can see an r rated movie) Else if age>=13{ write(you can see a pg 13 movie) else{ write(you can see a g rated movie);

So the first if statement is true for the adults and children, the else if statement is true but the adults already have a condition, so the second statement doesn't apply to the adults, but it should. That's why DON'T CHANGE THE ORDER. START WITH MOST SPECIFIC. Greater than 13 applies to adults and 14 year olds, be specific.

expression

a value, variable, operator, or procedure call, that returns another value

console.log("This\none\nstring\nprints\non\nmultiple\nlines");

This one string prints on multiple lines /n=line break

another most specific example:

Write the code for this^ if(temp>100) Its really hot Else if(temp>90) It's very hot Else if(temp>80) Its hot temp>70 It's warm Else It's cold important because above 70 is also above 80

syntax error

Your code doesn't follow the rules of the programming language. Writing a variable name in quotes Using a variable that doesn't exist.

logic error

Your code follows the rules of the programming language but doesn't do what you intend. Writing if-else-if statements in the wrong order. Updating the property of the wrong element.

arithmetic operator

addition, subraction, multiplication, division, and modulus operators

assignment operator

change the value represented by a variable. example: c=c+1

expression

combination of operators and values to evaluate to a single value. operators: list...

function call

command that executes the code within a function. like onEvent?

variables can't be in a string

console.log("petType")

this one problem i kept getting wrong

dayOfWeek= "Saturday" dayOfWeek= "Monday" If dayOfWeek=Saturday || dayOfWeek=Sunday Weekend function Else Weekday function DAY OF WEEK BECOMES MONDAY SO IT RUNS WEEKDAY FUNCTION

boolean expression

evaluates to true or false

check two boolean statements at once:

example with OR: Var age=3; If age>5 | | age>95 write("you get in for free") Else{ write("you must pay admission") example with AND: Var age=3; If age>12 && age<21 write("you get in for free") Else{ write("you must pay admission")

evaluate

expressions=a single value

function

giving a name to a set of actions. call it: type the name followed with (). An example of how computer scientists use ABSTRACTION to solve problems. Function: access repetitive information from one place Save space. If you want to change something, you only have to change it in one place in style 2. Helps you debug information. Only have to debug and update information in one place.

Scope of a variable: where the variable can be accessed. Variable are listed in the top lines, variables that are located outside of functions and events are referred as global variables-----one of the first lines of a program. Declare the variables first. That allows you to access the variables anywhere in your program If you declare a variable inside an event, it would only be accessible inside that event. This would be known as a local variable.

global: permanent. local: temporary. JUST MAKE SURE YOU TAKE THE VAR OUT OF ONEVENTS FOR NOW.

Procedure

group of programming instructions that have parameters and return values

if-else-if

if statement: false else-if true: runs else-if. can have multiple else-if. if: if statement: false. else-if false. then run else statement. default statement. Enter most specific condition first.

comparison operators

indicate a BOOLEAN expression. <, >, <=, >=, ==, !=. different from logical operators which are: AND, OR, NOT

concatenation

joins multiple strings to make a new string

Photoliker app

myComment=getText("commentInput") oldComment=getText("commentOutput")+myComment

K=9 G="APCSP" Display(K) Display(G) Display("K") Display("G") This would display: 9 APCSP K G(because the K and G are in quotes)

problem i got wrong

function

progamming instructions. KNOWN AS A PROCEDURE, FOR ALL THOSE PROCEDURE QUESTIONS.

variable

reference to a value that is used throughout the program

if the day is monday, and your age is 25 for this ^

the day part is false, the age part is false, the whole statement ends up being false

conditional statements

true or false value from a boolean expression that affects the program. conditional statements tell the computer to run the specific code if the statement is true.

relational operator

used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example: =, ≠, >, <, ≥, and ≤. WHAT'S THE DIFFERENCE BETWEEN THIS AND A RELATIONAL OPERATOR

Selection

what parts of the program are executed due to true or false condition

string

words and characters


Ensembles d'études connexes

Midterm 2 Material: Topic 4- Gene Interaction, Inheritance and phenotype and Topic 5-

View Set

Football Stars Messi and Ronaldo Audio Bio from http://www.famouspeoplelessons.com/ Glossary in English and Catalan by mnaves3

View Set

Life and Health: Life Insurance Policies

View Set

The Lightning Thief Chapters 5-9 Review

View Set

Hematologic Alterations CH 46 (E3)

View Set

MGMT 340 - Learn Start-Up (Introduction: Ch. 8)

View Set

Kinkle 1082 Final (EXAM II - EXAM IV)

View Set