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 / 8
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

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

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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