Summer 2007
week 1: 5/11
hi everybody,
sorry i didn't post this earlier. i've actually been rather ill since our class on friday night. in any case, i did say that you needed to check this blog over the course of the week to find out what you homework for our second class this week.
as mentioned in class, please make sure you purchase the required text and bring it to class. i will be checking to see who has the book and who doesn't. also, i want you all to find out the definition of the term variable in JavaScript, and then demonstrate its use with the alert() function that we learned in our last class.
good luck, carter-
sorry i didn't post this earlier. i've actually been rather ill since our class on friday night. in any case, i did say that you needed to check this blog over the course of the week to find out what you homework for our second class this week.
as mentioned in class, please make sure you purchase the required text and bring it to class. i will be checking to see who has the book and who doesn't. also, i want you all to find out the definition of the term variable in JavaScript, and then demonstrate its use with the alert() function that we learned in our last class.
good luck, carter-
- TOPICS:
- HOMEWORK: see homework above in the introductory note.
- INTRODUCE:
- JavaScript Data Types
- Numerical Data—This is perhaps the easiest data type to recognize as it pertains to something that we can intuitively recognize, things that we deal with on a daily basis, numbers. It includes all numbers, both positive (greater than zero) and negative (less than zero), integers (whole numbers such as 1, 2, 3, -17, 200, etc.), and decimals (1.5, .23, 22.87, etc). Moreover, it also includes numerical expressions; that is, numbers expressed in terms of equations, simple equations such as 1 + 1, more complex equations such as 5 * ((5 + 1) / (25 - 8)), as well as much more complicated mathematical equations that include geometrical, algebraic, and trigonometric functions, and calculus.
- String Data—This type is also relatively intuitive as the term itself, STRING, refers simply to a 'string of characters' set between quotation marks. The term characters here refers to any alpha-numeric character (numbers and letters), both lower and upper case, the hypen, the underscore, as well as all the other characters used in HTML. String data can be common English, such a a word ("hello"), a phrase ("very good food"), or longer strings such as sentences or paragraphs, or even whole 'pages' of HTML. Or, it may be some non-sensical series of character lined-up one after the other.
- Boolean Data—This type simply includes the values TRUE and FALSE, and their numerical equivalents, 1 and 0.
- Numerical Data—This is perhaps the easiest data type to recognize as it pertains to something that we can intuitively recognize, things that we deal with on a daily basis, numbers. It includes all numbers, both positive (greater than zero) and negative (less than zero), integers (whole numbers such as 1, 2, 3, -17, 200, etc.), and decimals (1.5, .23, 22.87, etc). Moreover, it also includes numerical expressions; that is, numbers expressed in terms of equations, simple equations such as 1 + 1, more complex equations such as 5 * ((5 + 1) / (25 - 8)), as well as much more complicated mathematical equations that include geometrical, algebraic, and trigonometric functions, and calculus.
- JavaScript Basic Built-in Functions
- You have also been introduced to some basic built-in JavaScript functions. Remember, a function is a an action that JavaScript takes. The built-in functions we have covered up to now are as follows:
- alert()—This is perhaps the easiest function to remember as it causes the browser to display a small 'alert' window. It is designed as a ONE-WAY communication of information (data) from the browser or script to the user. It is NOT interactive in that the user cannot respond by sending any information of his/her own.
- document.write()—Like the alert(), the document.write() is designed as a ONE-WAY communication of information (data) from the browser or script to the user. It is NOT interactive in that the user cannot respond by sending any information of his/her own; however, it does not produce an alert box. Instead, the information is 'written' directly into the browser window, the page itself, otherwise known as the 'document'. For this reason, the information sent from the script or browser, may also contain HTML or CSS.
- prompt()—This function is similar to the alert box in that it produces a small window that pops up above the browser window. Furthermore, like the alert(), some information or data is sent by the script to the user, usually in the form of a request for information. However, as a result of this 'request', this function IS in fact interactive which makes it a TWO-WAY exchange of information. This is because the user must provide some data of his/her own back to the script. The user thusly affects the outcome of the script. The type of data the user sends back is restricted only by the request made.
- confirm()—This function is also similar to the alert function in that it produces a small window that pops up above the browser window. Furthermore, it is similar to the prompt() function as well in that this function is also interactive. The user here must also provide some data of his/her own back to the script, and likewise affecting the outcome. However, the type of data the user sends back may only be in the form of boolean data as the space provided for responding to the request in the confirm box comes only in the form of 2 buttons, OKAY (true) and CANCEL (false). The request, then, must fit the restraints of this model in that TRUE or FALSE must be satisfactory responses.
EXAMPLES:
Good—Click okay if you need more time.
Bad—What color is your hair?
- parseInt()—This function is different than the other four listed above in that it does not necessarily produce any physical changes or results, such as the appearance of a pop-up window, or the change of the appearance of the web-page itself. What it does is perhaps more typical of most JavaScript functions as it works internally on the script itself, more specifically, altering the data within the script somehow. The task of this function is to change one type of data into another type of data, from STRING DATA to NUMERICAL DATA. The term parseInt means to parse the data provided as an integer; and broken down into plain English, means to PROCESS THE INFORMATION AS A NUMBER. The string data is placed between the parentheses, and the function, parseInt(), will therefore convert it from a string to a number, such as:
parseInt("1001") = 1001 >> converting the string "1001" to the integer 1001.
- alert()—This is perhaps the easiest function to remember as it causes the browser to display a small 'alert' window. It is designed as a ONE-WAY communication of information (data) from the browser or script to the user. It is NOT interactive in that the user cannot respond by sending any information of his/her own.
- Variables—A variable in JavaScript is a special item. It serves as a container, like a cup, but which instead of containing liquids and drinks stores a single piece of information, or data. Once created, a variable may contain any piece of data of any type (numerical, string, boolean), but it may only contain one element of data at a time. This piece of data that it stores is known as its value. Moreover, this value may be changed at any time and as many times as required.
A variable is created, or declared with two things:- var keyword
- unique name
A variable is then given some data to hold, assigned a value, by using the assignment operator = and then its value. To give a variable some data, to assign it a value, for the first time is called initializing a variable.- declaring a variable —> var myName
- initializing a variable —> myName = "Carter"
- var keyword
- Concatenation—Technically, this is just one of many different JAVASCRIPT OPERATIONS; however, because of its importance and widespread, ubiquitous usage, I have discussed it since the first class. Furthermore, I believe it deserves review and mention here. Its actual definitions are as follows:
- To connect or link in a series or chain.
- (Computer Science) To arrange (strings of characters) into a chained list.
"Hello, " + "how are you?"
result in the longer string
—> "Hello, how are you"
Here are some other examples of concatenation:
"Carter" + "Johnson",
— "CarterJohnson"
"March" + 11, — "March11"
"March" + "11", — "March11"
"March + 11", — "March + 11"
"March + 11 =" + "March" + "11",
— "March + 11 = March11"
- To connect or link in a series or chain.
- JavaScript Data Types
0 Comments:
Post a Comment
<< Home