# Aantekeningen tijdens een cursus - **numbers** (e.g. 4, 10) - **strings** (e.g. "dogs go woof!") - **booleans** (e.g. true, false, 5 > 4) - **console.log**() = printing outcome - **condition** is tussen de ( ) - **syntax** = taal, termen. - **Statement** = if (condition) - **condition** - **inputs** - **function** - **return** The return keyword simply gives the programmer back the value that comes out of the function.  - GlobalVar = Var outside a function - Local Variable = var in a function - Scope = bereik ```javascript if (condition)  {     // if condition is true     // do this code } else // "otherwise" {     // do this code instead } ``` **Dingetjes** - > Greater than - < Less than - <= Less than or equal to - >= Greater than or equal to - === Equal to - !== Not equal to - = vergelijken - ( ): control order of operations (bij rek) - * and /: multiplication and division - - and +: subtraction and addition - **Modulo**: When % is placed between two numbers, the computer will divide the first number by the second, and then return the remainder of that division. (13 % 7 evaluates to 6) - Math.random() that variable will equal a number between 0 and 1. **Modulo** 5%2 = 1 (oneven) 4%2 = 0 (even) **Doeners** - **confirm**("I am ok");  - **prompt**("Are you ok?”); - **string length** (e.g. "Emily".length); - //**comment** - **console.log** - **return** - **for loop** - **arrays** VOORBEELD console.log("Xiao Hui".length < 122); console.log("Goody Donaldson".length > 8); console.log(8*2 === 16); alles is true **Strings** - **Substring**, deel van orginele volledige string - ”laptop".substring(3,6);  _From 4th to 6th letter of "laptop" uitkomst is top_ **Variabelen** - declare: var varName = data; - **Declare** a var is een var een naampje geven - de var inzetten dmv =varName - de var een functie (**function**) geven met {} - console.log("Hey" + "you"); will print out Heyyou. That's not what we want! - If you want a space between words, you must add that space as well! - console.log("Hey" + " " + "you"); will print out Hey you - This joining of strings is called **concatenation** VOORBEELD VAR MAKEN + INZETTEN ```javascript var myCountry = "string"; console.log(myCountry.length); ``` VOORBEELD FUNCTIO MAKEN `var greetings = function ( _parameter_ ) { _reusable code_  }` _Every line of code in this block { } must end with a ;._ _Functie oproepen:_ `greetings(“tekst”)` VOORBEELD VAR MET FUNCTION ```javascript var divideByThree = function (number) {     var val = number / 3;     console.log(val); }; divideByThree(12); ``` VOORBEELD SUBSTRING `console.log(myCountry.substring(0,3));` **TIPS** - The computer doesn't worry about extra spaces between words or brackets - It just cares about the order of where things are placed and that you have used the right characters (){}[]""; - For extra help, a program called a 'linter' is checking your code and will put a red 'x' next to the first line that contains errors - At the end of each line of code (within the { }) and after the entire function (after the { }), please put a semi-colon. The semi-colon acts like a period in a sentence. It helps the computer know where there are stopping points in the code. - D.R.Y. **VOORBEELD** ```javascript var myFinish = "I finished my first course!"; var myFail=“string fuck yout” if (28 === 28)if {     console.log(myFinish); } else {     console.log(“myFail”); } ``` VOORBEELD ```javascript _declare function:_ var foodDemand = function (food)  _Herbruikbare code_ {     console.log("I want to eat" + " " + food); }; _call:_ foodDemand("burrito's"); ``` **VAR IN VAR** ```javascript var orangeCost = function (price) {     var total = (price * 5);     console.log(total); }; orangeCost(3); ``` Je koopt altijd 5 oranges. De prijs wisselt en kun je in veranderen bij de call  **RETURN VOORBEELD** ```javascript _// Parameter is a number, and we do math with that parameter_ var timesTwo = function(number) {     return number * 2; }; _// Call timesTwo here!_ var newNumber = (timesTwo(4)); console.log(newNumber); ``` **FOR LOOP** ```javascript for (var i = 1; i < 11; i = i + 1) {     /* your code here */; } ``` **LOOP regels** **Rules to learn** a. A more efficient way to code to increment up by 1 is to write i++. b. We decrement down by 1 by writing i--. c. We can increment up by any value by writing i += x, where x is how much we want to increment up by. e.g., i += 3 counts up by 3s. d. We can decrement down by any value by writing i -= x. (See the Hint for more.) e. Be **very** careful with your syntax—if you write a loop that can't properly end, it's called an **infinite loop**. It will crash your browser! **ARRAYS** ```javascript var names = ["Mao","Gandhi","Mandela"]; var sizes = [4, 6, 3, 2, 1, 9]; var mixed = [34, "candy", "blue", 11]; var arrayName = [data, data, data]; - Any time you see data surrounded by [ ], it is an array. - the position (or the index) of each bit of data is counted starting from 0, not 1. var junkData = ["Eddie Murphy", 49, "peanuts", 31]; console.log(junkData[3]) ```