Unit 3 - programming

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

Increment:

++ eg. a ++ is the same thing as: a = a + 1 or a += 1

Iteration:

- process of repeating a set of instructions or a code block multiple times.

Deciment:

-- eg. a -- is the same thing as: a = a - 1 or a -=1

Math.min()

returns the smallest number between two values

Math.pow()

this method allows you to raise a number to a power

How to trace variables in loops?

use console logging or debugging techniques.

Math.random()

Generates a random floating point number between 0 & 1.

How to write a truth table

Kolla Yt

Solving complex boolean

Kolla yt

Logical Operators

Logical operators perform logical operations on boolean values. -AND (&&) -OR (||) -NOT (!)

Bitwise Operators

Manipulate individual bits of integers. -AND (&) -OR (|) - XOR (^). (If input bits are the same, then the output will be false(0) else true(1).) -complement (~) : Flips all 0s into 1s and all 1s into 0s. Eg. 5 = -6 - left shift (<<): Moves the bits of binary to left by how many <. and right shift (>>). : Moves the bits of binary to left by how many >.

Math.sqrt

Returns the square root of a number

3.1 Arithmetic Operators

The symbols +, -, *, /, %, and ^ used to perform mathematical operations on numeric values.

Assignment Operators

Used to assign values to variables. They include the basic assignment operator (=) compound assignment operators: -Addition: += -Substraction: -= -Multiplication:*= -Division: /= -Calculating the remainder when the left operand is divided by the right operand and assigns the result back to the left operand. %= These perform an operation and assign the result to the variable.

What is a counter?

a variable that is regularly incremented or decremented each time a loop iterates

Boolean comparisons

= : Equal to > : Greater than < : Less than

3.5 Logical Operators

AND (&&): The AND operator returns true if both operands are true. Otherwise, it returns false. OR (||): The OR operator returns true if at least one of the operands is true. If both operands are false, it returns false. NOT (!): The NOT operator is a unary operator that reverses the logical state of its operand. It returns true if the operand is false and returns false if the operand is true.

Relational Operators

Comparing two values and return a boolean result. - They include equality (==) - Not equal to (!=), - Greater than (>), - Less than (<), - Greater than or equal to (>=) - Less than or equal to (<=).

For loops:

Control flow statement that allows you to repeatedly execute a block of code based on a specified condition.

How to generate a random integer

Eg. Return random integer between 0-9: Math.floor(Math.random() * 10); Eg. Return random integer between 0-100: Math.floor(Math.random()*100) + 1;

What does a break statement do

Exits the currently executing loop Eg. for (let i = 0; i < 5; i++) { if (i === 3) { break; } console.log(i); }

Difference between while and for loops:

For loop is used when the number of iterations is already known. While loop is used when the number of iterations is already Unknown.

3.4 while Loops

repeatedly execute a block of code as long as a specified condition evaluates to true. The loop will continue executing as long as the condition remains true.

For loop from lowest to highest

// Loop from the lowest value (1) to the highest value (10) for (let i = 1; i <= 10; i++) { console.log(i); }

Order of precedence logical operators:

1. NOT (!): - If true, ! returns false - If false, ! returns true 2. AND (&&): - If true for both values, && returns true - If false for both values, && returns false 3 OR (II): - If first operand true, II returns true - If first operand false, II returns value for second operand

Math.abs()

absolute value

Math.max()

returns the largest number between two values

Errors in loops

initiation error

How to use "while" loops example:

let count = 0; while (count < 5) { console.log("Count: " + count); count++; }

If statement example

let num = -5;if (num > 0) { console.log("The number is positive."); } else { console.log("The number is not positive."); }

If else statement example

let num = 0;if (num > 0){ console.log("The number is positive."); } else if (num < 0) { console.log("The number is negative."); } else { console.log("The number is zero."); }

If else If else statement example

let num = 10; if (num > 0) { console.log("The number is positive."); } else if (num < 0) { console.log("The number is negative."); } else { console.log("The number is zero."); }


Ensembles d'études connexes

Solving for side lengths of right triangles

View Set

Chapter 8: The designers: Scenery and costume part 1

View Set