Docsity

JavaScript For Loop and Nested Loops with Arrays and Error Handling, Study notes of Computer Science

Partial preview of the text

Download JavaScript For Loop and Nested Loops with Arrays and Error Handling and more Study notes Computer Science in PDF only on Docsity!

Announcements

 Check class announcements daily

 You must implement programming projects by yourself

For Loop

 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

One-Dimensional Arrays

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

 What is Top-Down Design?

 Let’s go over an example

Video Store Software

 Bottom-Up Design

Top-Down Design