campus.murraystate.edu

Download Report

Transcript campus.murraystate.edu

JavaScript

Background  Developed by Brandon Eich  Mid 1990s  Originally called Mocha  Has nothing to do with Java

Purpose  Interpreted Language  Utilized on multiple platforms  Not designed as a standalone language  Easy to incorporate in HTML  Light-weight, very portable

Variables  Container for storing data  Dynamic Typing  Must begin with a letter  Can consist of numbers, letters, $ and _  Case Sensitive  Variables are declared using var

Data Types  String  Number  Boolean  Array  Undefined  Null

If Else if (time<20) { x="Good day"; { } else x="Good evening"; }

Switch  var day=new Date().getDay();  switch (day)  {  case 0:   x="Today it's Sunday"; break;  case 1:   x="Today it's Monday"; break;  case 2:   x="Today it's Tuesday"; break;  case 3: x="Today it's Wednesday";

For Loop for (var i=0;i");

While and Do While while (i<5) { x=x + "The number is " + i + "
"; i++; } do { x=x + "The number is " + i + "
"; i++; } while (i<5);

Functions } Function myFunction(side1, side2) { var side3 = sqrt((side1*side1) + (side2*side2)); return side3; var ans = myFunction(side1, side2);

Objects  Just Data with properties and methods  Almost everything can be an Object  Created by using: Person = new Object();  A property is called using: Person.age;  A method is called using: Person.name.toUpperCase();

Error Handling

My First JavaScript

Example Code – Alert Message    

Click the button to display an alert box.