Variables and Conditions

by Haig. Average Reading Time: about a minute.

Let’s first look at an example:


There are several concepts that we should know. First of all, var x= is a variable declaration. If you want to create a variable, you must declare the variable using the var statement. x will get the result, namely, true or false. Then we use a condition statement if else to give the script the ability to choose between two paths, depending on this result (condition for the following action). If the result is true (the user clicked “ok”), “Thank you” appears in the window box. If the result is false (the user clicked “cancel”), “Good choice” appears in the window box instead.

We can make more complex message boxes using var, if and those basic methods.


Another example:

			Welcome to my website!.

If you click “cancel”, it will take you to my website, and clicking ok will continue with the loading of the current page “Welcome to my website!”. Note: if (!x) means: if click “cancel”. In JavaScript, the exclamation mark ! means: “none”.

Next Up: Function

No comments on ‘Variables and Conditions’

Leave a Reply