Hey,
This is a basic tutorial that I have written about javascript.
What is javascriptjavascript is a client-side scripting languages which is mainly used to make webpage better. It is probably the most popular scripting language, which is thought of as a lower programming language.
The basics & laying out javascriptIf you know CSS you will find this bit very easy as it is basically the same but with different syntax, you need to open your javascript tag.
CODE
<script type="text/javascript">
<!--
javascript Code Here
//-->
</script>
This doesn't exactly do much but it has opened your javascript tag and closed it; also you can link to an external javascript file just like in CSS.
CODE
<script type="text/javascript" src="javascript.js">
This will link to the directory that you are on and pull the 'javascript.js file and use it, just like the external CSS file. We will start with the most common javascript basics which are document write and alert.
CODE
<script type="text/javascript">
<!--
document.write("13Dots - javascript Tutorial");
//-->
</script>
This will execute the '13Dots - javascript Tutorial' onto your webpage with the default styling and really won't do anything, but you can play around with it for example.
CODE
<script type="text/javascript">
<!--
document.write("<b>13Dots</b> - javascript Tutorial");
//-->
</script>
You can guess what this does as it uses the basic HTML tag for bold, you can use things like H1 but not like you actually use this tag too much so we will move on.
alerts are one of the most common yet
most annoying scripts you will ever see. It simply opens a horrible pop-up on your web browser.
CODE
<script type="text/javascript">
<!--
alert("13Dots - javascript Tutorial");
//-->
</script>
Now this will output in a pop-up box '13Dots - javascript Tutorial' and will just annoy the hell out of users so I recommend that you stay away from it when not needed.
VariablesVariables are in javascript as it is basically a programming language, you may have seen them in PHP or Visual Basic etc but they are also in javascript and here is how you define them and use them in your webpage.
CODE
<script type="text/javascript">
<!--
var name = "Dan Williamson"
document.write(name);
//-->
</script>
This will define the variable 'name' to hold 'Dan Williamson' and then excecute it onto the webpage using document write. You can also do maths with it etc but I won't show you how to do that in this tutorial as I won't go too in-depth, this is just the major basics of javascript, I will be writing another one tomorrow with will feature:
- Functions
- Operators
- Conditions
- If/Else
Hope you liked this.