Embed presentation
Downloaded 795 times
















































![JAVASCRIPT ARRAYS• Arrays store a sequence of items, accessible via an indexsince javascript is loosely typed, elements do not have to be the same type• To create an array, allocate space using new (or can assign directly)• ITEMS = NEW ARRAY(10); // ALLOCATES SPACE FOR 10 ITEMS• ITEMS = NEW ARRAY(); // IF NO SIZE GIVEN, WILL ADJUST DYNAMICALLY• ITEMS = [0,0,0,0,0,0,0,0,0,0]; // CAN ASSIGN SIZE & VALUES []• To access an array element, use [] (as in c++/java)• FOR (I = 0; I < 10; I++) {• ITEMS[I] = 0; // STORES 0 AT EACH INDEX• }• The length property stores the number of items in the array• FOR (I = 0; I < ITEMS.LENGTH; I++) {• DOCUMENT.WRITE(ITEMS[I] + "<BR>"); // DISPLAYS ELEMENTS• }](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-49-2048.jpg&f=jpg&w=240)
![ARRAY EXAMPLE<html><!–- COMP519 js10.html 11.10.2011 --><head><title>Die Statistics</title><script type="text/javascript"src="http://www.csc.liv.ac.uk/~martin/teaching/comp519/JS/random.js"></script></head><body><script type="text/javascript">numRolls = 60000;dieSides = 6;rolls = new Array(dieSides+1);for (i = 1; i < rolls.length; i++) {rolls[i] = 0;}for(i = 1; i <= numRolls; i++) {rolls[randomInt(1, dieSides)]++;}for (i = 1; i < rolls.length; i++) {document.write("Number of " + i + "'s = " +rolls[i] + "<br />");}</script></body></html>suppose we want tosimulate die rolls andverify even distributionkeep an array ofcounters:initialize each count to0each time you roll X,incrementrolls[X]display each counter](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-50-2048.jpg&f=jpg&w=240)



![<!DOCTYPE html><html><head><script>function validateForm() {var x = document.forms["myForm"]["fname"].value;if (x==null || x=="") {alert("First name must be filled out");return false;}}</script></head><body><form name="myForm" action="demo_form.asp" onsubmit="returnvalidateForm()" method="post">First name: <input type="text" name="fname"><input type="submit" value="Submit"></form></body></html>](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-54-2048.jpg&f=jpg&w=240)



HTML is a markup language used to define the structure and layout of web pages. It uses tags like <h1> and <p> to mark headings and paragraphs. CSS is used to style and lay out HTML elements, using selectors, declarations, and properties to change things like colors and positioning. JavaScript can be added to HTML pages with <script> tags and is used to add interactive elements and dynamic behavior by manipulating HTML and responding to user input. It has data types like strings and numbers and control structures like if/else statements.
















































![JAVASCRIPT ARRAYS• Arrays store a sequence of items, accessible via an indexsince javascript is loosely typed, elements do not have to be the same type• To create an array, allocate space using new (or can assign directly)• ITEMS = NEW ARRAY(10); // ALLOCATES SPACE FOR 10 ITEMS• ITEMS = NEW ARRAY(); // IF NO SIZE GIVEN, WILL ADJUST DYNAMICALLY• ITEMS = [0,0,0,0,0,0,0,0,0,0]; // CAN ASSIGN SIZE & VALUES []• To access an array element, use [] (as in c++/java)• FOR (I = 0; I < 10; I++) {• ITEMS[I] = 0; // STORES 0 AT EACH INDEX• }• The length property stores the number of items in the array• FOR (I = 0; I < ITEMS.LENGTH; I++) {• DOCUMENT.WRITE(ITEMS[I] + "<BR>"); // DISPLAYS ELEMENTS• }](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-49-2048.jpg&f=jpg&w=240)
![ARRAY EXAMPLE<html><!–- COMP519 js10.html 11.10.2011 --><head><title>Die Statistics</title><script type="text/javascript"src="http://www.csc.liv.ac.uk/~martin/teaching/comp519/JS/random.js"></script></head><body><script type="text/javascript">numRolls = 60000;dieSides = 6;rolls = new Array(dieSides+1);for (i = 1; i < rolls.length; i++) {rolls[i] = 0;}for(i = 1; i <= numRolls; i++) {rolls[randomInt(1, dieSides)]++;}for (i = 1; i < rolls.length; i++) {document.write("Number of " + i + "'s = " +rolls[i] + "<br />");}</script></body></html>suppose we want tosimulate die rolls andverify even distributionkeep an array ofcounters:initialize each count to0each time you roll X,incrementrolls[X]display each counter](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-50-2048.jpg&f=jpg&w=240)



![<!DOCTYPE html><html><head><script>function validateForm() {var x = document.forms["myForm"]["fname"].value;if (x==null || x=="") {alert("First name must be filled out");return false;}}</script></head><body><form name="myForm" action="demo_form.asp" onsubmit="returnvalidateForm()" method="post">First name: <input type="text" name="fname"><input type="submit" value="Submit"></form></body></html>](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2foverview-161028103409%2f75%2fAn-Overview-of-HTML-CSS-Java-Script-54-2048.jpg&f=jpg&w=240)

