Javascript - Getting Good with Loop and Array

906 views

Published on

Getting Good with Loop and Array

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
906
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Javascript - Getting Good with Loop and Array

  1. 1. Javascript: Looping TCB1033 [email_address]
  2. 2. Looping Structure in Javascript <ul><li>for repetition statement </li></ul><ul><ul><li>example eg_for_01.html </li></ul></ul><ul><li>while repetition statement </li></ul><ul><ul><li>example eg_while_01.html </li></ul></ul><ul><li>do … while repetition statement </li></ul><ul><ul><li>example eg_do_while_01.html </li></ul></ul>
  3. 3. Javascript: Array TAB1033 [email_address]
  4. 4. Agenda <ul><li>Introduction </li></ul><ul><li>Arrays </li></ul><ul><li>Declaring and Allocating Arrays </li></ul><ul><li>Examples Using Arrays </li></ul><ul><li>Example 1: Random Image Generator Using Arrays </li></ul><ul><li>Example 2: Simple Quiz </li></ul>
  5. 5. Introduction <ul><li>Arrays </li></ul><ul><ul><li>Data structures consisting of related data items </li></ul></ul><ul><ul><li>Sometimes called collections of data items </li></ul></ul><ul><li>JavaScript arrays </li></ul><ul><ul><li>“ dynamic” entities that can change size after they are created </li></ul></ul><ul><li>An element may be referred to by giving the name of the array followed by index of the element in square brackets ( [] ) </li></ul>
  6. 6. … Introduction <ul><li>The first element in every array is the zeroth element. </li></ul><ul><li>The i th element of array c is referred to as c[i-1] . </li></ul><ul><li>Every array in JavaScript knows its own length, which it stores in its length attribute and can be found with the expression arrayname .length </li></ul>
  7. 7. Declaring and Allocating Arrays <ul><li>JavaScript arrays are Array objects. </li></ul><ul><li>Creating new objects using the new operator is known as creating an instance or instantiating an object </li></ul><ul><li>Operator new is known as the dynamic memory allocation operator </li></ul>
  8. 8. Creating Two New Arrays
  9. 9. Creating + Initialise Arrays <ul><li>Arrays can be created using a comma-separated initialiser list enclosed in square brackets ( [] ) </li></ul><ul><ul><li>The array’s size is determined by the number of values in the initialiser list </li></ul></ul><ul><li>The initial values of an array can be specified as arguments in the parentheses following new Array </li></ul><ul><ul><li>The size of the array is determined by the number of values in parentheses </li></ul></ul>
  10. 10. … Creating + Initialise Arrays
  11. 11. Manipulating Array Elements
  12. 12. Example 1: Random Images <ul><li>eg_random_image.html </li></ul>
  13. 13. Example 2: Simple Quiz <ul><li>quiz.html </li></ul>

×