110 likes | 268 Views
Introduction to JavaScript. Week 1 - Presentation 1 Veronica Noone. Objectives. What is JavaScript? Why JavaScript? What can it do? HTML Review <script> tag Our First Script Lab 01 - bgcolor changer. What is JavaScript?. Interpreted Computer Language Not compiled
E N D
Introduction to JavaScript Week 1 - Presentation 1 Veronica Noone
Objectives • What is JavaScript? • Why JavaScript? • What can it do? • HTML Review • <script> tag • Our First Script • Lab 01 - bgcolor changer
What is JavaScript? • Interpreted Computer Language • Not compiled • Code get’s interpreted every time it is executed (run) • It’s NOT Java - originally LiveScript • Just needs a browser to run • Can run locally no need to “serve”
Why JavaScript? • Supported by the most common browsers • Versatile • Can be used with within PDF files • Easy to learn • It’s FUN!
What can it do? • Interact with users • Validate user data • Automate tasks • Calculators • “Tricks” • Rollovers • Scrolling text With some Inventiveness and Creativity you can do a lot!
Examples • http://www.nhlbisupport.com/bmi/ • http://student.ccbcmd.edu/~vnoone • Warning!! Some of these are EXTREME! • http://domscripting.com/domsters/index.html • http://script.aculo.us/ • http://www.themaninblue.com/writing/perspective/2005/10/05/slideshow/index.htm • http://www.scottschiller.com/
Ok, let’s take a look but first… • HTML Review <html> <head> <title>Sample Test Page</title> </head> <body> <h1>Basic HTML structure</h1> <p>This is just a sample HTML page with a head, a body and a few tags</p> </body> </html>
<script> tag • Informs the browsers built in JavaScript interpreter to run the code • The text of the code is not shown to the user • Can go in the head or the body <script language="javascript" type="text/javascript"> <!--// //code goes here // --> </script>
Our First Script <html> <head> <title>Our First Script</title> <script language="javascript" type="text/javascript"> <!--// alert("First Script Block in Head"); // --> </script> </head> <body bgcolor="white"> <h1>Our First Script - Heading 1</h1> <script language="javascript" type="text/javascript"> <!--// // Script block 1 alert("First Script Block after Head"); // --> </script> <p>Paragragh 1</p> <script language="javascript" type="text/javascript"> <!--// // Script block 2 document.bgColor = "red"; alert("Second Script Block after paragragh"); // --> </script> <p>Paragragh 2</p> <script language="javascript" type="text/javascript"> <!--// // Script block 2 document.bgColor = "blue"; alert("Third Script Block"); // --> </script> </body> </html> No Seriously, Let’s take A look • Go to the class web page • Right click on w01p01ex01.html and save the file to your desktop
Things to notice… • // • document.bgcolor • Alert() function • Message is the parameter • Modal • ; • Semicolons end a statement
Week 01 Lab 01 Background Color Changer • Code a document to alert the user of a background color change 3 times. • For example… • Page loads • user is alerted that the BG color will change to red. The BG changes to red • user is the then alerted the BG will change to green, the BG changes, • you get the idea. • CHALLENGE: Use only one script tag • Lab worth 10 points