10-26-2012, 06:05 AM
I feel very bad today and i don't know how many errors i will have or how bad i will expain it but i hope you will undarstand it if you have problem ask in comments
I hope that you have undarstand part 1 in this part we will cover Functions, If...Else, Switch
Function
A function is a block of code that will be executed when somebody call it, in JavaScript functions are very used
Exaple
On the first line we give a name to the function (MyFunction in the example)
between {} is the body of the function (the code we what to use later[when we call the function]))
And now let's call it
This code is simple to undarstand i hope you deal with it
Calling function with arguments
When you call a function you can pass along some values to it these values are called arguments or parameters
example
Here we give values to name and name1
and the function work with those 2 arguments you can have 5-10 even 1235135351325 arguments on function
If...Else
if statement - use this statement to execute some code only if a specified condition is true
if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false
if...else if....else statement - use this statement to select one of many blocks of code to be executed
switch statement - use this statement to select one of many blocks of code to be execute
If statment example
if the times is between 13 and 18 the program will alert (have a nice day)
If...else Statement
If its < than 20 it will alert good day if its > than 20 it will alert good evening
If...else if...else Statement
If the time is less than 10:00, you will get a Good morning alert if not but the time is less than 20:00 you will get a Good day alert otherwise you will get a Good evening alert
Switch
We use the switch statement to select one of many blocks of code to be executed
Example
Display today's weekday-name. Note that Sunday=0, Monday=1, Tuesday=2, etc
Don't forget to write break; afther each case !
I hope that you have undarstand part 1 in this part we will cover Functions, If...Else, Switch
Function
A function is a block of code that will be executed when somebody call it, in JavaScript functions are very used
Exaple
Hidden Content
On the first line we give a name to the function (MyFunction in the example)
between {} is the body of the function (the code we what to use later[when we call the function]))
And now let's call it
Hidden Content
This code is simple to undarstand i hope you deal with it
Calling function with arguments
When you call a function you can pass along some values to it these values are called arguments or parameters
example
Hidden Content
Here we give values to name and name1
Hidden Content
and the function work with those 2 arguments you can have 5-10 even 1235135351325 arguments on function
If...Else
if statement - use this statement to execute some code only if a specified condition is true
if...else statement - use this statement to execute some code if the condition is true and another code if the condition is false
if...else if....else statement - use this statement to select one of many blocks of code to be executed
switch statement - use this statement to select one of many blocks of code to be execute
If statment example
Hidden Content
if the times is between 13 and 18 the program will alert (have a nice day)
If...else Statement
Hidden Content
If its < than 20 it will alert good day if its > than 20 it will alert good evening
If...else if...else Statement
Hidden Content
If the time is less than 10:00, you will get a Good morning alert if not but the time is less than 20:00 you will get a Good day alert otherwise you will get a Good evening alert
Switch
We use the switch statement to select one of many blocks of code to be executed
Example
Hidden Content
Display today's weekday-name. Note that Sunday=0, Monday=1, Tuesday=2, etc
Don't forget to write break; afther each case !