Skip to main content

Posts

Showing posts from April, 2017

For loop

 Figure 1 Hope now you have a little idea about this flow chart. Here if the statement is true it go inside the loop and if the statement is false it will be end. To use this for loop you have to use an initialized counter. for(count = 0; count < 10; count++){ //statements to execute when the counter is less than 10 }   OK This is an simple example which use for loop to print even numbers from 0 to 10. Here you need not only for loop knowledge. You need also if else statement to check whether the number is even or not.                                                                        Figure 2 Look the output is here…                                                                     Figure 3

Variables

Hi people, this is my third js tutorial which explains about using variables with js. So, let’s move on. Before use variables we must declare variables. For that we have to use  var  keyword. Ex:         var first_name,last_name;      var age=23;       var country= “Srilanka”;       When we create functions in js we use local variables inside function. The specialty of local variable is the value of the local variable will destroy once it exits the function. So, the other thing is you can use global variable in anywhere within the js code. See the below code. Figure 1 Did you see? Here first I defined variable   var_   as a global variable. Then within the  variableChecking() , I declared   var_   again as a local variable. So, within the function it is a local var. But in outside the function it is a global variable. You can clearly understand it by run previous program. See the Figure 2 and Figure 3                                                    

if Statement

Think you are going to write a js program. And there is a conditional situation that you have to choose one decision out of set of decisions. So you have to use conditional statements as a solution for that problem. It is like this. Figure 1 So here what happen is if the condition is true the program is execute. But if it is not true it leaves the condition. Let’s take an example, There are two variables x and y. x is 10 and y is 12. So our condition is x==y ? (Does x equals y?)So what happen there is x and y both goes to the first box and then checks does x equals y ??? Then they come to a decision No No. x is not equal to y. So it go with 2 nd  path and program will end. That’s all. There is only one condition here. But we can use if for several conditions and also for nested conditions. Let’s move to an example with all together. Then you will learn all about if else in one program.                                              Here you can see

Use external JavaScript file

Hi people who are interest to learn js.  So this is the second simple tutorial and this will be very short and sweet one that describes about how to prevent using js within HTML tags. That means in this tutorial  will show you how to use external js file. Actually there is nothing new. So let’s move on. If you see my first js tutorial you know that we wrote our js programs within HTML tags. So there is another solution to make our life easy. Lol…👻😂 Let’s start... Ok let’s take our last example that called js function by clicking a button in the webpage. See here…                                                   Figure 1                               Figure 2 To achieve this you have to write your js code in separate file and save it as name.js (look the way that I have saved my file (one.js)). Then write your html code separately. After that you can import your js file by adding the path of your js file. <script language="javascript"

introduction about JavaScript

Hi everyone, I’m Chamini prahskthi from SriLanka. And…. This is the beginning of my JavaScript tutorial. Hope you will interest to learn JavaScript from beginning. I hope to give you step by step guide to be expert about JavaScript. OK, Do you know??? JavaScript is a client side developing language. JavaScript can be used to control the web browser. So, Normally JavaScript is use for validations.  like, Check if you have enter and valid email address. Also JavaScript is use to perform events like button clicks. So let’s move to the lessons. For this developing purpose you just need a text editor like Notepad++, sublime text etc. Here I’ll use Notepad++ for demonstration purposes. First of all I must tell you this. You must have very simple html knowledge for learn JS (from here I use short form JS for JavaScript). Ok let’s move on… JS is used with in HTML tags. Normally it used within <head> tags. But it is okay to use anywhere in HTML source code.