Intermediate JavaScript
From Wikiversity
|
Please help develop this page
This page was created, but so far, little content has been added. Everyone is invited to help expand and create educational content for Wikiversity. If you need help learning how to add content, see the editing tutorial and the MediaWiki syntax reference. To help you get started with content, we have automatically added references below to other Wikimedia Foundation projects. This will help you find materials such as information, media and quotations on which to base the development of "Intermediate JavaScript" as an educational resource. However, please do not simply copy-and-paste large chunks from other projects. You can also use the links in the blue box to help you classify this page by subject, educational level and resource type. |
|
[edit] If-then Statements
If then statements are used to tell the browser if this happens, then do this. An if then statement is structured like this:
if (the condition)
{
code to run
}
For example you could make it so the browser prompts for the user to type in a their age, and if it is below 21 it would pop up an alert saying "no beer for you!". The code would be this:
var age = prompt("how old are you?","");
if (age < "21")
{
alert("no beer for you!")
}