Home arrow JavaScript arrow JavaScript Statements
JAVASCRIPT

JavaScript Statements


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.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 5
October 31, 2007
TABLE OF CONTENTS:
  1. · JavaScript Statements
  2. · If...Else
  3. · Switch Hitter
  4. · How to Enter Special Characters

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
JavaScript Statements
(Page 1 of 4 )

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.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials