



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An explanation of javascript for loops, nested loops, and the use of arrays along with error handling. It includes examples and instructions on how to implement for loops, nested loops, and one-dimensional arrays. Additionally, it covers the concept of top-down design with an example of video store software.
Typology: Study notes
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Iteration statement General form for (initialize; test; expression) statement basically equivalent to Initialize while (test) { statement expression } If more than one statement use { } Semicolons are required Beware of infinite loop if semicolon after ) Example: ForLoop.html Example: ForLoopVariations.html
Problem You need to keep track of the scores of students in a class Declaring and handling 50 variables is not an easy task Arrays come to the rescue Array Collection of values that can be treated as a unit or individually var a = new Array(4) You can visualize an array as a set of variables one after another Indexing We access an element using [ ] First element associated with index 0 (e.g., a[0]) An element of an array can be of any type and an array can hold different types of elements The length property represents the length of the array (e.g., a.length) We can print the contents of an array by using alert Example: ArrayEx.html
Definition of One-Dimensional Arrays Via array literal comma separated list of elements within square brackets var a = [2, 3, 5]; var b = []; // empty array Specified in the Array constructor var c = new Array(); var e = new Array(4); // defines array of size 4