• Like
Programming - Workshop 2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Programming - Workshop 2

  • 459 views
Published

This is the second part of my workshop on programming. We continue on loops, start with conditionals and explain arrays.

This is the second part of my workshop on programming. We continue on loops, start with conditionals and explain arrays.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
459
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
43
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Programming Cas Lemmens - Workshop 2
  • 2. Regarding the feedback... I don’t get what I’m doing... ➡ This is normal! It’ll get specific soon! Programming is just not my thing... ➡ Same thing! This is very raw! I’ve already seen this! ➡ Make sure you come next time =)
  • 3. What did we see last time?
  • 4. What did we see last time? Variables var welcome:String = “Hello World!”;
  • 5. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * %
  • 6. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * % Boolean logic < > <= => == !=
  • 7. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * % Boolean logic < > <= => == != Loops: while-loop
  • 8. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  • 9. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  • 10. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  • 11. Procedural programming Loops
  • 12. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  • 13. Common loops While-loop For-loop Do while-loop
  • 14. while loop while(condition) { // Do something } The loop will keep on going until the condition is false.
  • 15. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  • 16. while loop while(condition) { // Do something }
  • 17. while loop var counter:Number = 1; while(condition) { // Do something }
  • 18. while loop var counter:Number = 1; while(counter < 11) { // Do something }
  • 19. while loop var counter:Number = 1; while(counter <= 10) { // Do something }
  • 20. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { // Do something }
  • 21. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  • 22. while loop ! Infinite loop
  • 23. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  • 24. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 25. do-while loop do { // Do something } while (condition);
  • 26. while(condition) { // Do something } do { // Do something } while (condition);
  • 27. for loop for(initialize, condition, update) { // Do something } The loop will start with the initialization, and do the update after every loop. The loop will keep on going until the condition is false.
  • 28. for loop for(initialize, condition, update) { // Do something }
  • 29. for loop 1 for(initialize, condition, update) { // Do something }
  • 30. for loop 1 for(initialize, condition, 2 update) { // Do something }
  • 31. for loop 1 for(initialize, condition, 2 update) { // Do something 3 }
  • 32. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  • 33. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  • 34. What did we initialize before the loop? var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 35. What did we initialize before the loop? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 36. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  • 37. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  • 38. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 39. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 40. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  • 41. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  • 42. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 43. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 44. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); 4 counter = counter + 1; }
  • 45. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  • 46. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  • 47. for loop 1 for(var counter:Number = 1, counter <= 10, 2 counter = counter + 1) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  • 48. while-loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  • 49. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } }
  • 50. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  • 51. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  • 52. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  • 53. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  • 54. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  • 55. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  • 56. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  • 57. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  • 58. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  • 59. Exercise 6 for-loop
  • 60. Procedural programming Conditionals
  • 61. Conditionals if and else switch
  • 62. if and else if (condition) { // Do something } else { // Do something else }
  • 63. if and else if (condition) This happens { when the // Do something condition is true } else { // Do something else }
  • 64. if and else if (condition) { // Do something } else This happens { when the // Do something else condition is false }
  • 65. var trashCount:int = 12; if (trashCount <= 0) { trace(“Your trash is empty.”); } else { trace(“Your trash contains” + trashCount + “ items.”); }
  • 66. if (condition1) { // Do something } else { // Do something else }
  • 67. if (condition1) { // Do something } else if (condition2) { // Do something } else { // Do something else }
  • 68. if (condition1) This happens { when condition 1 // Do something is true } else if (condition2) { // Do something } else { // Do something else }
  • 69. if (condition1) { // Do something } This happens else if (condition2) when condition 1 { is false and // Do something condition 2 is true } else { // Do something else }
  • 70. if (condition1) { // Do something } else if (condition2) { // Do something } else This happens { when condition 1 // Do something else and 2 are false }
  • 71. var language:String = “FR”; if (language == “FR”) { trace(“Bonjour!”); } else if (language == “SE”) { trace(“Hej!”); } else if (language == “NL”) { trace(“Hallo!”); } else { trace(“Hello!”); }
  • 72. Exercise 7 if and else
  • 73. switch (condition) { case condition1: // Do something break; case condition2: // Do something break; default: // Do something break; }
  • 74. switch (condition) { case condition1: This happens when // Do something condition 1 is true break; case condition2: // Do something break; default: // Do something break; }
  • 75. switch (condition) { case condition1: // Do something break; This happens when case condition2: condition 1 is false and // Do something condition 2 is true break; default: // Do something break; }
  • 76. switch (condition) { case condition1: // Do something break; case condition2: // Do something break; This happens when default: condition 1 and // Do something condition 2 are false break; }
  • 77. var language:String = “FR”; switch (language) { case “FR”: trace(“Bonjour!”); break; case “SE”: trace(“Hej!”); break; case “NL”: trace(“Hallo!”); break; default: trace(“Hello!”); break; }
  • 78. var language:String = “FR”; var language:String = “FR”; switch (language) if (language == “FR”) { { case “FR”: trace(“Bonjour!”); trace(“Bonjour!”); } break; else if (language == “SE”) case “SE”: { trace(“Hej!”); trace(“Hej!”); break; } case “NL”: else if (language == “NL”) trace(“Hallo!”); { break; trace(“Hallo!”); default: } trace(“Hello!”); else break; { } trace(“Hello!”); }
  • 79. Exercise 8 switchin’
  • 80. Procedural programming Arrays
  • 81. Array = a data-structure that can encompass multiple individual data values in an ordered list
  • 82. Array = a list of things
  • 83. “apple” “pear” “orange” “lemon” “banana” “pineapple” “strawberry”
  • 84. 11232 22343 34 423 0 23 1224
  • 85. “apple” “pear” “orange” “lemon” “banana” “pineapple” “strawberry”
  • 86. “apple” “pear” Element “orange” “lemon” “banana” “pineapple” “strawberry”
  • 87. 0 “apple” 1 “pear” Element 2 “orange” 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  • 88. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  • 89. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  • 90. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” Size of array? 6 “strawberry”
  • 91. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” Size of array? 6 “strawberry” 7
  • 92. Making an array
  • 93. Making an array Empty array: var fruits:Array = new Array();
  • 94. Making an array Empty array: var fruits:Array = new Array(); Array with a certain size: var fruits:Array = new Array(3);
  • 95. Making an array Empty array: var fruits:Array = new Array(); undefined Array with a certain size: var fruits:Array = new Array(3); undefined undefined
  • 96. Making an array Empty array: var fruits:Array = new Array(); undefined Array with a certain size: var fruits:Array = new Array(3); undefined Array with a certain elements: undefined var fruits:Array = new Array(“apple”, “pear”, “banana”);
  • 97. Making an array Empty array: var fruits:Array = new Array(); “apple” Array with a certain size: var fruits:Array = new Array(3); “pear” Array with a certain elements: “banana” var fruits:Array = new Array(“apple”, “pear”, “banana”);
  • 98. Making an array Empty array: var fruits:Array = new Array(); “apple” Array with a certain size: var fruits:Array = new Array(3); “pear” Array with a certain elements: “banana” var fruits:Array = new Array(“apple”, “pear”, “banana”); var fruits:Array = [“apple”, “pear”, “banana”];
  • 99. Getting an element
  • 100. Getting an element var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”);
  • 101. Getting an element “apple” “pear” var fruits:Array = new Array(“apple”, “orange” “pear”, “orange”, “lemon” “lemon”, “banana”); “banana”
  • 102. Getting an element 0 “apple” 1 “pear” var fruits:Array = new Array(“apple”, 2 “orange” “pear”, “orange”, 3 “lemon” “lemon”, “banana”); 4 “banana”
  • 103. Getting an element
  • 104. Getting an element “apple” “pear” “orange” “lemon” “banana”
  • 105. Getting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 106. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” 4 “banana”
  • 107. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” 4 “banana”
  • 108. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” singleFruit is “banana” 4 “banana”
  • 109. Getting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 110. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[8]; 3 “lemon” 4 “banana”
  • 111. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[8]; 3 “lemon” singleFruit is undefined 4 “banana”
  • 112. Changing an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 113. Changing an element 0 “apple” 1 “pear” 2 “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  • 114. Changing an element 0 “apple” 1 “pear” 2 “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  • 115. Changing an element 0 “apple” 1 “pear” 2 “raspberry” “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  • 116. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 117. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[5] = “strawberry”; 3 “lemon” 4 “banana”
  • 118. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[5] = “strawberry”; 3 “lemon” 4 “banana” 5 “strawberry”
  • 119. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 120. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana”
  • 121. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana” 5 undefined
  • 122. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana” 5 undefined 6 “grape”
  • 123. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 124. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” 3 “lemon” 4 “banana”
  • 125. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” 3 “lemon” 4 “banana” 5 “strawberry”
  • 126. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” push adds the element 3 “lemon” to the end of the array. 4 “banana” 5 “strawberry”
  • 127. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 128. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana”
  • 129. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana” 5 “strawberry”
  • 130. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana” 5 “strawberry” 6 “pinapple”
  • 131. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 132. Adding an element 0 “apple” 1 “pear” fruits.unshift(“strawberry”); 2 “orange” 3 “lemon” 4 “banana”
  • 133. Adding an element 0 “strawberry” 1 “apple” fruits.unshift(“strawberry”); 2 “pear” 3 “orange” 4 “lemon” 5 “banana”
  • 134. Adding an element 0 “strawberry” 1 “apple” fruits.unshift(“strawberry”); 2 “pear” 3 “orange” unshift adds the element to the beginning of the array. 4 “lemon” 5 “banana”
  • 135. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 136. Adding an element 0 “apple” 1 “pear” fruits.unshift(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana”
  • 137. Adding an element 0 “pineapple” 1 “apple” fruits.unshift(“strawberry”, 2 “pear” “pineapple”); 3 “orange” 4 “lemon” 5 “banana”
  • 138. Adding an element 0 “strawberry” 1 “pineapple” fruits.unshift(“strawberry”, 2 “apple” “pineapple”); 3 “pear” 4 “orange” 5 “lemon” 6 “banana”
  • 139. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 140. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before
  • 141. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  • 142. Deleting an element 0 “apple” 1 “pear” 2 “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  • 143. Deleting an element 0 “apple” 1 “pear” 2 “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  • 144. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  • 145. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5
  • 146. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5 5
  • 147. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5 = 5
  • 148. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” delete changes the value to undefined 4 “banana” Size before Size after 5 = 5
  • 149. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 150. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  • 151. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” 4 “banana” Size before 5
  • 152. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” 4 “banana” Size before 5
  • 153. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before 5
  • 154. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5
  • 155. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5 4
  • 156. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5 != 4
  • 157. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” pop removes the last 3 “lemon” element from the array Size before Size after 5 != 4
  • 158. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  • 159. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  • 160. Deleting an element 0 “apple” 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  • 161. Deleting an element 0 “apple” 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  • 162. Deleting an element 0 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  • 163. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before 5
  • 164. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5
  • 165. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5 4
  • 166. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5 != 4
  • 167. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” shift removes the first element from the array Size before Size after 5 != 4
  • 168. Splice-method splice( startIndex:Number, [deleteCount:Number], [value:Object]); split + slice = splice Startindex Deleting parts of an array DeleteCount Add elements to an array Value
  • 169. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” 3 “lemon” 4 “banana”
  • 170. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” fruits.splice(2); 3 “lemon” 4 “banana”
  • 171. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” fruits.splice(2); 3 “lemon” 4 “banana”
  • 172. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined fruits.splice(2);
  • 173. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined fruits.splice(2); splice with only a startindex, deletes all elements after the startindex
  • 174. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” 3 “lemon” 4 “banana”
  • 175. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  • 176. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  • 177. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  • 178. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 Value = not defined fruits.splice(1,3); “banana”
  • 179. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “banana” Value = not defined fruits.splice(1,3);
  • 180. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “banana” Value = not defined fruits.splice(1,3); splice with a startindex and a deletecount, will delete a given up serie of elements
  • 181. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” 3 “lemon” 4 “banana”
  • 182. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” fruits.splice 3 “lemon” (2,0,”strawberry”); 4 “banana”
  • 183. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” 5 “banana”
  • 184. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” 5 “banana”
  • 185. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” splice adds elements by giving up the position with 5 “banana” startindex, and setting deletecount to 0
  • 186. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” 3 “lemon” 4 “banana”
  • 187. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” fruits.splice (2,0,”strawberry”, 3 “lemon” “raspberry”); 4 “banana”
  • 188. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 fruits.splice (2,0,”strawberry”, 3 “raspberry”); 4 “orange” 5 “lemon” 6 “banana”
  • 189. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice (2,0,”strawberry”, 3 “raspberry” “raspberry”); 4 “orange” 5 “lemon” 6 “banana”
  • 190. Splitting with splice
  • 191. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array();
  • 192. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits1: 0 “apple” 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  • 193. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  • 194. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  • 195. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  • 196. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 0 “orange” 1 “pear" 1 “lemon” 2 “banana”
  • 197. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); fruits2: 0 “orange” 1 “lemon” 2 “banana”
  • 198. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); fruits1.concat(fruits2); fruits2: 0 “orange” 1 “lemon” 2 “banana”
  • 199. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); 2 “orange” fruits1.concat(fruits2); 3 “lemon” fruits2: 4 “banana”
  • 200. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”);
  • 201. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length;
  • 202. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6
  • 203. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6 Printing out the array: fruits.toString();
  • 204. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6 Printing out the array: fruits.toString(); return apple,pear,orange,orange,lemon, banana,pineapple,strawberry
  • 205. Array methods
  • 206. Array methods Adding fruits.unshift(); fruits.push();
  • 207. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop();
  • 208. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop(); Splice fruits.splice(2); fruits.splice(2,2); fruits.splice(2,0,”apple”);
  • 209. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop(); Splice Other fruits.splice(2); fruits.length; fruits.splice(2,2); fruits1.concat(fruits2); fruits.splice(2,0,”apple”); fruits.toString();
  • 210. Exercise 9 Arrays
  • 211. No homework, but please... Overlook it... Experiment with it... Ask questions! Remember: this is only the start! So please, get this!
  • 212. Q&A
  • 213. Thanks!