15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

494<br />

Designing User Interfaces<br />

JavaScript arrays can store any type of data, such as integers, decimal<br />

values, strings, or Boolean values like this:<br />

var myarray = [93.42, “Hi there”, 3];<br />

Another way to create a JavaScript array is to define the array size and then<br />

store data in that array like this:<br />

var myarray = new Array(x);<br />

Here x is the size of the array, such as 4 or 9. After defining an array, you can<br />

store items in that array like this:<br />

myarray[2] = “This works”;<br />

JavaScript arrays are zero-based, which means if you define an array like<br />

this:<br />

var myarray = new Array(2);<br />

The array elements are numbered myarray[0], myarray[1], and<br />

myarray[2].<br />

Designing User Interfaces<br />

JavaScript can retrieve data from the user by creating different types of user<br />

interface elements, such as dialog boxes and windows. Such user interface<br />

items can display in<strong>for</strong>mation to the user, creating an interactive Web page.<br />

Creating dialog boxes<br />

The three types of dialog boxes JavaScript can create are alert, confirmation,<br />

and prompt. An alert dialog box displays a message on the screen and gives<br />

the user the option of closing the dialog box. A confirmation dialog box displays<br />

a message and offers the user two or more choices. A prompt dialog<br />

box gives users a chance to type in data.<br />

To create an alert dialog box, you need to define the text you want displayed,<br />

such as<br />

alert(“Message here”);<br />

An alert dialog box displays an OK button. As soon as the user clicks this OK<br />

button, the alert dialog box goes away.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!