Unformatted text preview:

SSE 3200 Javascript Lab (Part 1 of 2)IntroductionJavascript is a programming language designed to run in web environments. Even though the namecontains “Java”, Javascript is not related to Java other than being a high level programming lan-guage. Javascript has the basic language contructs but it much more limited in scope as comparedto Java. It is called a “scripting language” due to its limited scope.The most common usage of Javascript is from html documents. The Javascript portions are taggedas scripts, and the browser calls the interpreter to execute the Javascript commands.The most important feature of Javascript is that it runs on the client machine. In contrast, PHPscripts run on the server machine.Basics1. Go to the JS How to page at http://www.w3schools.com/js/default.asp.2. Try out the second example that prints ”Hello World!” in H1 fonts.3. Change the example such that it prints:Hello World! How are you today?4. Type the following line after the line containing document.write and before the end tagof the script:alert("We are doing a SSE3200 lab right now.");It will display an alert box.1Alert box in the header1. Go to the JS Where to page.2. Run the first example under the title “Scripts in <head>”.3. Add another function below the message function:function add(x,y){return x+y;}4. Run the example to observe that the behavior does not change.5. Add a call to the add function by changing the alert line:alert("Did you know that the result is: " + add(7,8) + "?");6. Run the example to the text and the result printed in the alert box.2If-then-statements1. Browse the sections on JS Statements, JS Comments, JS Variables, JS Operators, and JSComparisons.2. Go to the If . . . Else page.3. Run the second example which prints “Good morning” if the time is less than 10, and “Goodday” otherwise.4. Add the following lines after the declaration of time:var day = d.getDay();document.write(" The Date is: " + d + "<BR>");document.write(" The hour is: " + time + "<BR>");document.write(" The day is: " + day + "<BR>");5. Run the modified example.6. Browse the JS Switch section.3Buttons1. Go to the JS Popup Boxes page.2. Run the “Alert Box” example.3. (You will be graded on the following.)Change the example so that it prints seven buttons labeled with the days of the week. Thebuttons should be preceded by the text ”Click on your favorite day:” If the current day isthe same as the favorite day, display an alert box that says ”Today is your favorite day!”Otherwise display an alert box tells how many days they have to wait for their favorite day.4. E-mail me your script with ”favorite day script” on the subject


View Full Document

MTU SSE 3200 - Javascript Laboratory

Download Javascript Laboratory
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Javascript Laboratory and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Javascript Laboratory 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?