SunQuest
 
       JavaScript
  Home arrow JavaScript arrow JavaScript Statements
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM developerWorks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript Statements
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2007-10-31

    Table of Contents:
  • JavaScript Statements
  • If...Else
  • Switch Hitter
  • How to Enter Special Characters

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    JavaScript Statements


    (Page 1 of 4 )

    In our last tutorial we covered where to place JavaScript code, how to work with variables, and print stupid things to the screen. In this installment we will be working with Conditional Statements, Switch Statements, and if there is time, Operators. So call up your date and cancel (who am I kidding? You'd rather go on a date than study this) and let's get to work.

    On One Condition

    We've all been given conditions before, especially if you've ever been mugged. If you give me all your money I won't beat you up. If you give me all your money, then I will beat you up. Give me your money and I won't beat you up, or else I will beat you up and take your money. Those are all good examples of conditional statements. They simply state "do this and this happens."

    There are four types of Statements in JavaScript. They are the If Statement, the If...Else statement, the If...Else If...Else Statement, and the Switch Statement.

    What If

    What if I weren't a fat nerd? What if I had a name like Beauregard Iffington the Third and owned a big fat yacht? What if Gary Coleman wrestled an alligator? Would it still be hungry afterwards?

    Okay that isn't how an If Statement works. It's just some questions that have been plaguing me lately. An If Statement says if this condition is true, do this. Here is how that looks in code:

     

    <html>

    <body>


    <script type="text/javascript">

    var job = “Computers”


    if (job == “Computers”)

    {

    document.write("<b>You must be fat.</b>")

    }

    </script>

    </body>

    </html>

    In the above example, we assigned the value Computers to a variable we named job. We then made an if statement that stated if the value of jobs is Computers, print something out. Since the value of jobs does match the criteria of our if statement, the following would print out to the screen:

      You must be fat.

    If the value of job had been anything else, nothing would have happened.

    More JavaScript Articles
    More By James Payne


       · Thanks for dropping by the read my article on Javascript. In this exciting episode...
     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway