WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1Accespted JavaScript - Functions Mon Mar 12, 2012 11:31 pm

Mr.Joker

Mr.Joker
Mr. WebArtz
Mr. WebArtz
JavaScript - Functions
Working with functions in JavaScript


Hello again gays, I am Mr.Joker and I will show you how to use functions in javascript. Let me explain what is a function first. A function is specific action that will be preformed with a name. Umm, you will say: "Hey man, I dont get it yet.". Well if this sound apstract, elts use some life example. There is a lot of functions in life like , runing, jumping, making breakfast etc. Lets take jumping to explain how function work. First you do before jump is crouch and then powerfull jump upward. Thats two actions inside one function. And we call all actions with one name, a function. So elts do an example wit javascript to udnerstand maybe even more better:

Code:
<script type="text/javscript">
function test() {
document.write("Hello World!");
}
</script>
We have here a function we named test. You see that we first write function so our web browser understand we wil lname a funcion, and then we give a name to function. I gived some random name like test. Ok, so whats new in this tutorial? Well the function i wrote can not be used yet. Why not? Because a function will be executed when i tell to her: "To it now.". Thats good, because imagine i write code in javascript that i want to preform only if someting happend. And if there is no function, my code will be executed anytime i run javascript which is so stupid. With function i can control how peace of code will work. Now I am the boss Very Happy . Lets see another example:

Code:
<script type="text/javascript">
function test() {
var x = "Hello World."
document.write(x);
}
document.write(x);
</script>
What we have here? We have same function from source above, and one more command to write "Hello World." but with using a variable from function. As you can see inside a function is variable and that variable only belong to that function and nobody else. So when we say to our browser to preform this code he start like this. Ok , there is a function, get it, there is a variable inside function, ok get it, there is a command to write that variable on the screen, ok cool i will do it. Function closed with } mark. And then another code to write text on the screen with variable from function. And then something strange happend. A function say: "Hey man, its my variable, i will not give it to you.". So, we cant use a variable that belong to a function. Its not possible. Why I explain you this? Its because you have to understand that function is like a another javascript inside a javascript. So you write a milion peaces of code and run it when you want. No need to run all at once. So how to run a function? Well we have to use events. Huh? What is event man? Let me explain it to you like this. You all visit forums and web sites around the globe and you saw events every day, for example: link hover, image hover, text hover, text change color, text change font, etc... So thats all events. When we do something on website with are mouse by passing over image its event, but the action it is preformed after event is done is a function. I hope you understand that. Lets try to use real life explanation. I know I am bad in it, but hey, if you know better tell me Very Happy . Imagine the example with jumping. The event could be moment when a friend tell you : "Jump now. ". So thats a event, and as soon as event happend a function start to preform. But in javascript function must always preform when event happen, in real life you can say to your friend: "I dont want to jump.". Very Happy
So here is example:

Code:
<html>
<title>Test</title>
<head>
<script type="text/javascript">
function test() {
var x = "Hello World."
document.write(x);
}
</script>
</head>
<body onLoad="test()">
</body>
</html>
I wont explain to you HTML code in javascript tutorial because I think you sohuld know allready HTML if you want to learn javascript. Here we have in body tag something new. its a onLoad="test()". I told to our web browser to preform a function whenever page is loaded. So if you reload page, the function will be preformed again on same way. There is a bunch of different events i have to teach you, but hey, this tutorial is about functions, so in next tutorial i will explain you more about events and how to use them Very Happy .

Tutorial for WebArtz.

Notice : This tutorial is copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators.

2Accespted Re: JavaScript - Functions Wed Mar 14, 2012 7:21 pm

ankillien

ankillien
Administrator
Administrator
Tutorial Accepted

Thanks for your contribution Very Happy

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum