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

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

Pre 2010

Uploaded on 07/30/2009

koofers-user-ta8
koofers-user-ta8 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Announcements
Check class announcements daily
You must implement programming projects by yourself
1
pf3
pf4
pf5

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