Wednesday, April 6, 2011

Lab/ Class Work

Directions for Starting a Car.

Walk to the driver's side of the car.
Get the key into our hand.
Locate the keyhole on the driver-side door.
Placing the end that is not ridged between your thumb and index finger, insert the ridged part into the key hole on the driver-side door.
Turn the key clock-wise until you hear clicking/unlocking sound.
Remove the key.
Lift the door handle and open the driver-side door.
Swing the door all the open so that you can enter the car with your body.
Sit in the seat, to do this you place your butt into the seat.

What we learn from this exercise:
Before we start writing code we should start with psuedo-code and write in plain English the steps we plan to take.


Getting Started:
Create a new "site" in Dreamweaver (specify the folder where all the files will be).
Into the head:
<script type="text/javascript">
alert("hello world");

F12 (runs the page) 
alert - is just giving you one of those alert boxes

It makes a difference where you put the code. Generally we put the code into the head of the page.

Script in the head =
If you add some text to the body and then view the page, the alert will pop up before you are able to see whatever you typed into the body.

Script in the body =
So if you put the alert into the body after the paragraph text in the body, you will see the body text before the alert.

There are multiple ways in javascript to comment-out code.

//single line
/* multi-line comment */

In the body
      document.write("hello world, but this time it's better.");

Grammar (aka syntax) of JS

Statements = usually represents a single step in a program
statements end with a semicolon;

"Commands" (commands is not an official title, just something we made up for this class) = functions or methods, they use parenthesis  ( blah do something blah )

Variable = container for data, a placeholder
 for example if we have the variable called name : we all have a name but since that name is different that variable called name has a different value.

= this is not an equal sign, it is the assignment operator meaning: set to the value of
equals is a completely different thing

2 Steps to create a variable:
    - declare the variable    var name;
    -  assign it a value         name =  "J-cubed";   

               -or-   var name = "J3";

    <h1>I am thirsty.</h1>
    <script type="text/javascript">

    //alert("hello world");
    var message;  //declared a variable
    message =  "hello world, but this time it's better."  //assign it a value
      document.write(message);   //write the message out to the page

Naming variables:
In JS it can only begin with a letter, $, or and _
var name, var $name, var _name
They can contain letters, numbers, $, _, camelCase  BUT NO SPACES
The variables are case sensitive

Variable Data Types
every variable you make has a specific data type, it tells you what kinda stuff is in that container
Also it informs you what you can do with it.
For example if you have a number you know you can do math on it, as opposed to a string.

We will be dealing 3 common data types:
Number- 5, 5.3, -5.3
String - any series of alphanumeric characters that are enclosed in quotes (you can use single or double quotes)
Boolean - true or false

var myVar ="5" this is a string
var myVar=5 this is a number
var hasCrap=true

Javascript is like html in that it doesn't care about white space.
But you can't put a carriage return in the middle of a string

No comments:

Post a Comment