Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> The Basics Of Javascript 2, Bit more advanced
DanWilliamson
post May 30 2006, 04:58 PM
Post #1


Regular Dot
Group Icon
Group: *Premier*
Posts: 56
Joined: 20-March 06
From: Manchester UK
Member No.: 10,400





I said I would write another basic javascript tutorial and I may go on a bit more but here it is.

Conditions like If/Else should be used if you want to make a certain condition be excecuted, for example.

CODE
<script type="text/javascript">
<!--
        var name = Dan;

    if (name == Dan)    
    {
    document.write("My name is Dan")
    }
//-->
</script>


So here we have defined the variable 'name' with the string 'Dan' and then we have used if (name) to tell the IF statement which variable to check whether the name is Dan. == is the operator for equal too which you will know if you did Maths in school or whatever, you can have varied responses instead of document write.

CODE
<script type="text/javascript">
<!--
    var name = Dan;

    if (name == Dan)    
    {
    alert("My name is Dan")
    }
//-->
</script>


This will execute it in an alert, also you can use the H1, H2 tags bold etc with the basic HTML tags, you can also add the else condition so that if the result turns back negative it can output something totally different. I have changed the variable in this one.

CODE
<script type="text/javascript">
<!--
    var name = Jimbo;

    if (name == Jimbo)    
    {
    document.write("My name is Dan")
        // This will return the correct result.
    }
      else
      {
      // This is where we can change it for example
      alert("13Dots rocks my pretty pink socks")
       }
//-->
</script>


You can go more advanced with this, but this is only a basic tutorial so perhaps another time victory.gif

Operators are easy and you can find references anywhere, these are the ones I find most useful.

CODE
+ - Plus
- - Take away
== Equal to
< - Less than
> - More than
* - Multyiply
&& - And


Functions are something I use quite a bit when coding javascript, as they can be really useful but sometimes quite difficult to grasp, to use a function you must 'call' it for it too work.

CODE
<script type="text/javascript">
<!--
function alert()
{
alert("13Dots - javascript Tutorial")
}
//-->
</script>

<!-- HTML or whatever here --!>

<script type="text/javascript">
<!--
document.write("alert()");
//-->
</script>


A breakdown of this is that you can use a function to store something until you call it when someone does something or even as soon as it loads, you use the 'function' to begin it and then your functionname() then you use the brackets as normal.

CODE
function functionname()
{
    // Function thingy here such as alert, document.write or whatever
}


Hope you understand this well enough as I plan on writing quite a few tutorials soon.
 
+Quote Post  Go to the top of the page
RedDragon
post May 30 2006, 10:29 PM
Post #2


insert coin
Group Icon
Group: Main Team
Posts: 5,344
Joined: 24-May 04
From: Maastricht
Member No.: 35





It's getting better and better! victory.gif

Thanks!
 
+Quote Post  Go to the top of the page
Eddie_K
post May 31 2006, 01:04 AM
Post #3


Hush now, I'm thinking...
Group Icon
Group: *Premier*
Posts: 3,977
Joined: 25-May 04
From: Heaven
Member No.: 47





Thanks for these. This way I'll learn javascript better too thumbsup.gif . Waiting for the following tuts.

Eddie
 
+Quote Post  Go to the top of the page

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 9th February 2010 - 06:43 AM
Wordpress Themes | Cyprus Property | Free Games | Car Insurance Quotes | iPod Sale