|
Web Systems and E-Commerce SPRING 2007 BU4035 |
|
Home | Syllabus | Journal | Project | Exam | Research | Gallery |
Thursday April 12th 2007
Next Tuesday we will have a guest speaker and food. (Provided by the Computer Club)
The JavaScript program below will put the date on the bottom of your page.
<script type="text/javascript">
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var dayarray=new
Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new
Array("January","February","March","April","May","June","July","August","September","October","November","December")
document.write("<span class='dates'>"+dayarray[day]+", "+montharray[month]+"
"+daym+", "+year+" ")
</script>
There are nine items that a JavaScript program can be evaluated against. Have at least seven of them.
1) You get THREE points for identifying the program as JAVASCRIPT.<SCRIPT LANGUAGE=>
2) You get SIX points for identifying the variable declaration. (Var).
3) You get THREE points for identifying input/output (prompt and write).
4) You get NINE points for identifying if or switch statement.
5) You get THREE points for identifying the loop (For or While).
6) You get THREE points for identifying function body and function call.
7) You get THREE points for identifying an object/object member and value.
8) If you identify an Event you get THREE points
9) You get THREE points for identifying array.
JavaScript is a language that is embedded in HTML and is executed in a browser (Internet Explorer or Netscape). Almost every web page now utilizes JavaScript. While the name is JavaScript and people think it is related to Java, it is a distinct language by itself. Dealing with the Internet (Internet programming) is a common purpose of Java and JavaScript, and both are event-driven. The way JavaScript handles input (ex. an input value has to be parsed to its numerical value) is similar to Java. JavaScript can take advantage of HTML to make the page more presentable by using loops and if statements to manipulate many fonts, colors, etc. The syntax of JavaScript is very similar to that of C++ and JavaScript’s keywords are mostly from C/C++; out of 22 keywords, 17 are used in C++, 4 keywords are used in Pascal such as var, function, with, and in, and there are some other keywords such as null and typeof. The words write and writeln (write line) to display are also used in Pascal. JavaScript is an event-driven language that, upon certain events such as clicking the mouse or pressing a key, an action takes place.
Why do we need JavaScript?
1) JavaScript can be used as a lightweight program code to ensure validity of typed data , window environment changes (resize etc). JavaScript should not be used for security because the code is visible in the web browser and page source code.
CGI- CGI programming is C++ code that is accessed by a web server in a browser.
JavaScript programmers use code abbreviations (shorthand) to prevent novices from copying their code.
var errImg = (Image ? new Image(1, 1) the ? means IF
In Volume 2 of the text look on Page 696 at the bottom example on the page.
JavaScript does not require a compiler. You just type the code into your HTML code and most of today's web browsers can run the program.
JAVASCRIPT has a lot of built in functions.
Many people have already written programs for Javascript.
You just have to find them.
How do you know something is a search engine? If it has a LOOP (FOR, WHILE, DO WHILE)and there is some equality inside the loop.
JavaScript is it's own language it is not related to Java.
The anatomy of a JavaScript Search Page 696.
<HTML><H1>Javascript search</H1>
<SCRIPT LANGUAGE="javascript"> This tells the browser what language we're using.
var english=["water","house","book","university","car","computer"];
var spanish=["aqua","casa","libro","universidad","caro","computador"];
Variable Declaration var result = 0; var searchword = prompt("Enter english word to translate: "); for(i=0;i<english.length;i++){ THIS IS THE LOOP if(english[i]==searchword){ document.writeln("Spanish word: "+spanish[i]); IF STATMENT result = 1; }//IF }//FOR if(result==0) document.writeln("Sorry, NO MATCH for: " + searchword); OUTPUT </SCRIPT> </HTML>
See below for an example of this code in action.