Created
November 11, 2015 21:45
-
-
Save mrandri19/c95e0cbac1ebaaf688ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class: center, middle | |
| #Lezione 3 | |
| ##If, else, elseif e array | |
| --- | |
| #Espressioni | |
| ```js | |
| var a = 5; | |
| a==5 /* Questa è un'espressione, quando verrà eseguita*/ | |
| /*diventerà */ true | |
| var b = 3; | |
| a+b /* diventerà 8 */ | |
| ``` | |
| <br> | |
| Possono essere anche unite con le parentesi: | |
| ```js | |
| (8*3)-2 //22 | |
| 1.0 == 1 //true | |
| false != true //true | |
| (3*2)>5 && !false // true | |
| false || true //true | |
| "foo" + "bar" //"foobar" | |
| ("foo" + "bar") != false //true | |
| ((2-3)>-2) || ("giorgia" == "noemi") //cosa? | |
| ``` | |
| --- | |
| #If | |
| ```js | |
| if( condizione ) { | |
| codice da eseguire se la condizione è vera | |
| } | |
| ``` | |
| --- | |
| #Else | |
| ```js | |
| if (condizione) { | |
| codice da eseguire se la condizione è vera | |
| } else { | |
| codice da eseguire se la condizione è falsa | |
| } | |
| ``` | |
| --- | |
| #Elseif | |
| ```js | |
| if (condizione1) { | |
| codice da eseguire se la condizione1 è vera | |
| } else if (condizione2) { | |
| codice da eseguire se la condizione2 è vera | |
| } else { | |
| codice da eseguire se NESSUNA condizione è vera | |
| } | |
| ``` | |
| --- | |
| #Array | |
| Un modo di avere delle liste di variabili | |
| ```js | |
| var nome1 = "andrea"; | |
| var nome2 = "vincenzo"; | |
| var nome3 = "stefano"; | |
| var nome4 = "alessandro"; | |
| //MALE, BRUTTO | |
| ``` | |
| ```js | |
| var nomi = [ "andrea", "vincenzo", "stefano", "alessandro"]; | |
| //MEGLIO | |
| ``` | |
| Si accede al valore usando `variabile[ indice ]` | |
| Gli inidici partono da 0 | |
| ```js | |
| nomi[0] // "andrea" | |
| nomi[2] // cosa? | |
| ``` | |
| --- | |
| #Array #2 | |
| Anche una stringa è un array | |
| ```js | |
| var alfabeto = "abcdefgh" | |
| alfabeto[2] //cosa? | |
| ``` | |
| Per aggiungere un elemento ad un array. Lo aggiunge alla fine | |
| ```js | |
| var a = ['a', 'b', 'c', 'd']; | |
| a.push("e"); | |
| //a sará ["a", "b", "c", "d", "e"] | |
| ``` | |
| Per togliere un elemento dalla fine dell'array | |
| ```js | |
| var a = ['a', 'b', 'c', 'd']; | |
| a.pop(); | |
| //cosa? | |
| ``` | |
| --- | |
| #Array #3 | |
| Per ottenere la lunghezza dell'array (per fare la media ad esempio) | |
| ```js | |
| var a = ['a', 'b', 'c', 'd']; | |
| a.lenght(); | |
| //cosa? | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment