|
|||||||||||||||||||||||||||||||
Guissmo's Javascript (1)
Javascript is not that hard. You can easily get this even you're a total n00b.
Please take note that all of these codes should be in the <script> tag.
Like Math, Javascript has variables for you to control. To set a variable, all you have to do is to type the name of a variable, an equal sign, and the value.
You can also use strings, but they have to be in quotes.
You could also do operations with the variables.
That tiny code there adds the number of cars and vans to get the total number of vehicles. Now, based on the codes above, what do you think will vehicle equal to?
CORRECT! vehicle=8.
You could also add words to the numbers. For example:
You can see that variable statemnt will be equal to:
There are 3 cars and 5 vans. Isn't that lovely?
All the operations and everything happens behind the scenes, which means, the website viewer won't see it. Aww... poor website viewer. So, you have to write it down.
This little code will display... you guessed it!!!
It will display:
This is just an example
Wow!!! Isn't that cool?
Now, try doing this:
variable older and variable younger
are the ages of two different persons.
you want to get their age gap and display it.
now, try filling in the missing parts.
the final thing should display:
If the older one is 20, and the younger is 17, then their age gap is 3.
If this is the first time you learned this,
please post your answer so that I will tell you if it's correct or not.
Please write the whole code.
Thanks..
I will probably be continuing this, so stay tuned!
EDIT01: OMG I forgot that BB Code won't work inside the Code Tag!
Please take note that all of these codes should be in the <script> tag.
| Code: |
|
<script language="JavaScript"> //everything goes here </script> |
Like Math, Javascript has variables for you to control. To set a variable, all you have to do is to type the name of a variable, an equal sign, and the value.
| Code: |
|
cars=3 vans=5 |
You can also use strings, but they have to be in quotes.
| Code: |
|
banana="fruit" carrot="vegetable" trash="neither fruit nor vegetable" |
You could also do operations with the variables.
| Code: |
|
vehicles=cars+vans |
That tiny code there adds the number of cars and vans to get the total number of vehicles. Now, based on the codes above, what do you think will vehicle equal to?
CORRECT! vehicle=8.
You could also add words to the numbers. For example:
| Code: |
|
statement="There are "+cars+" cars and "+vans+" vans. Isn't that lovely?" |
You can see that variable statemnt will be equal to:
There are 3 cars and 5 vans. Isn't that lovely?
All the operations and everything happens behind the scenes, which means, the website viewer won't see it. Aww... poor website viewer. So, you have to write it down.
| Code: |
|
document.writeln("This is just an example") |
This little code will display... you guessed it!!!
It will display:
This is just an example
Wow!!! Isn't that cool?
Now, try doing this:
| Code: |
|
<script language="JavaScript"> older=20 younger=17 agegap=??? sentence=??? document.writeln(???) <script> |
variable older and variable younger
are the ages of two different persons.
you want to get their age gap and display it.
now, try filling in the missing parts.
the final thing should display:
If the older one is 20, and the younger is 17, then their age gap is 3.
If this is the first time you learned this,
please post your answer so that I will tell you if it's correct or not.
Please write the whole code.
Thanks..
I will probably be continuing this, so stay tuned!
EDIT01: OMG I forgot that BB Code won't work inside the Code Tag!
