Saturday, 21 August 2021

 Java Script

Loop, Function ,Validation, Regular Expression

Example:1


<!doctype html>

<html>

<head>

<title> Java script-Loop</title>

</head>


<body>

    <script>


    for(i=0;i<=12;i++)

    {

       

        if(i==5)

        {

            x=i;

            continue; 


        }

  

    document.write(i);

    document.write("</br>");

    }


    document.write("number" +x+ "is missing in above list");

      

   </script>


</body>

</html>



Example :2

<!doctype html>
<html>
<head>
<title> Java script-Switch-Case</title>
</head>

<body>
    <script>

var d=new Date();
ch=d.getMonth();
//var m=1;


switch(ch)
{

case 1:document.write("jan");
break;
case 2:document.write("feb")
break;
case 3:document.write("mar")
break;
case 4:document.write("apr")
break;
case 5:document.write("may")
break;
case 6:document.write("june")
break;
case 7:document.write("july")
break;
case 8:document.write("aug")
break;
case 9:document.write("sep")
break;
case 10:document.write("oct")
break;
case 11:document.write("nov")
break;
case 12:document.write("dec")
break;
}
   
   </script>

</body>
</html>



Example 3:

<!doctype html>
<html>
<head>
<title> Java script-Event</title>

    <script>

        function check()
        {
            var eno,name;
            eno=document.getElementById("eno").value;
            name=document.getElementById("name").value;
        
        document.write("eno"+eno+ "name"+name+"");
            alert("Enrollment No." + eno+ "Name"+name+"");
        }
            
        
        
           </script>
</head>

<body>
   
<form name="myfrm">
   <label>eno</label>
   <input type="text" name="eno" id="eno">

   <label>name</label>
   <input type="text" name="name" id="name">

   <input type="submit" id="submit" onclick="check()">
</form>
</body>

</html>

Example 4:

<!doctype html>
<html>
<head>
<title> Java script-Function</title>

    <script type="text/javascript">
    var x=mul(10,20);

    document.write("</br>answer:" +x);

    function mul(x,y)
    {
        document.write("x:=" +x);
        document.write("y:=" +y);
        return x*y;

    }
</script>
</head>
</body>
</html>

Example 5:

<!doctype html>
<html>
<head>
<title> Java script-Validation</title>
<script type="text/javascript">
function chk(eno1,pass1)
{
    //var eno=document.f1.eno.value;  
   // var pass=document.f1.pass.value;
    
    var eno1=document.getElementById("eno").value;
    var pass1=document.getElementById("pass").value;


    if(eno1=="163" || eno1=="160")
    {  
    alert("enter proper eno");  
    return false;  
    }
    else if(pass1.length>6)
    {  
    alert("Password must be at least 6 characters long.");  
    return false;
    }  
   return true;
}  
  </script>
  </head>
        <body>
            <form name="f1" action="#">
            <table border="1">
            <tr>
                <td>Enrollment No.:</td>
                <td><input type="text" size="30" name="eno"></td>
            </tr>

            <tr>
                <td>Password.:</td>
                <td><input type="password" size="30" name="pass"></td>
            </tr>

            <tr rowspan="3">
            <td><input type="submit" value="check" onclick="chk()"></td>
            </tr>

            </table> 
            </form>   
       </body>
</html>


Example 6:

<!DOCTYPE html> 
<html> 
  
<head> 
   <title> Java script-Regular Expression/title>
    <script type="text/javascript"> 
        function test_str() { 
            var res; 
            var str = 
                document.getElementById("t1").value; 
            if (str.match(/[a-z]/g) && str.match( 
                    /[A-Z]/g) && str.match( 
                    /[0-9]/g) && str.match( 
                    /[^a-zA-Z\d]/g) && str.length >= 8) 
                res = "TRUE"; 
            else 
                res = "FALSE"; 
            document.getElementById("t2").value = res; 
  
        } 
    </script> 
</head> 
  
<body oncontextmenu="return false" onLoad="disableClick()"> 
    <p> 
        String: 
        <input type="text"  placeholder="abc"  id="t1" /> 
        <br/> 
        <br/> 
        <input type="button"
               value="Check" 
               onclick="test_str()" /> 
        <br/> 
        <br/> Output: 
        <input type="text"   id="t2"  readonly/> 
    </p> 
</body> 
  
</html> 


Example 7:

<!doctype html>
<html>
<head>
   <title> Java script-Validation</title>
<script>
 
function validemail()  
{  
var x=document.myfrm.email.value;  
var atposition=x.indexOf("@");  
var dotposition=x.lastIndexOf(".");  
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length)
{  
  alert("Please enter a valid e-mail address \n atpostion:"+atposition+"\n dotposition:"+dotposition);  
  return false;  
  }  
}  
</script>  
<body>  
<form name="myfrm"  method="post" action="#" onsubmit="return validemail();">  
Email: <input type="text" name="email"><br/>  
  
<input type="submit" value="register">  
</form>  
</body>
</html>

Example 8:

<!doctype html>
<html>
<head>

   <title> Java script-Validation</title>
<script>

function w(f1)
{

var pass=document.f1.pass.value;

if(pass.length ===0)
{
    alert("enter your password 3 char long");
    return false;
}
return true;
}

</script>
</head>
<body>
<form name="f1">

Password<input type="text" name="pass" size="30">

<input type="submit" name="submit" onclick="w()">

</form>

</body>
</html>


Example 9:

<!doctype html>
<html>
<head>
<title> Java script-Dialog box</title>

    <script type="text/javascript">
        function check()
        {
    alert("hello world");

        }
    </script>

</head>
<body>
    <script type="text/javascript">
        check();
</script>

</body>
</html>


Example 10:

<html>
   <head>   
<title> Java script-Function</title>
      <script>
         function sayHello(name, age) {
            document.write (name + " is " + age + " years old.");
         }
      </script>      
   </head>
   
   <body>
   
      <form name="myfrm">
         <input type = "button" onclick = "sayHello('James', 33)" value = "Say Hello">
      </form>      
  
   </body>
</html>





Monday, 16 August 2021

 Java Script

Function, Dialog Box, Validation and Regular Expression

Example:1

<html>   

   <head>

      <title>Form Validation</title>      

      <script type = "text/javascript">


        function validform()

        {

            var fname=document.f1.fname.value;

            var pass=document.f1.pass.value;


               if(fname==null||fname=="")

               {

                alert("name cant be blank");

                return false;


               }

               if(pass.length<6) 

               {

                    alert("password must be atleast 6 char long");

                    return false;


               }

               

             alert("both are correct");

             return true;


        }


    </script>

    </head>

<body>


   <form name="f1">


    Name:<input type="text" name="fname" size="20" placeholder="enter your full name"></br>

    Password:<input type="password" name="pass" size="20" placeholder="enter your password"></br>

    

    <input type="submit" name="submit" onclick="validform()">


   </form>

    

</body>

</html>



Example 2:


<!doctype html>

<html>

<head>

<title>Java Script-Function</title>

<script>


function swap()

{

var a,b,temp;

a=Number(document.getElementById("f").value);

b=Number(document.getElementById("s").value);


temp=a;

a=b;

b=temp;


document.getElementById("ans1").value= a;

document.getElementById("ans2").value= b;

}


</script>

</head>


<body>

Value of a: <input id="f">

Value of b: <input id="s"></br></br>


<button onclick="swap()">Swap</button></br></br>

Value of a: <input type="text" name="ans1" id="ans1">

Value of b: <input id="ans2" name="ans2" id="ans2">


</body>

</html>


Example 3:


<!doctype html>

<html>

<head>


<script>


function prod(price,taxrate,balance)

{

    

    var total=price+price*taxrate;


    if(total<=balance)

    {

        alert("Yes");


    }

    else

    {


        alert("No");


    }


}



</script>

</head>


<body>


   Price <input type="text" name="price">

   Balance <input type="text" name="balance">

    Tax Rate<input type="text" name="taxrate">


    <input type="button" value="Go" onclick="prod()">


</body>

</html>



Example:4


<html>   

   <head>

      <title>Form Validation</title>   

    <script>


      function showdttime()

      {

            document.getElementById("demo").innerHTML = Date();


           // document.myfrom.date1.value=Date();

      }



      function changebackground(val)

      {


           // var text1=""            ;


            

        if(val=='red')

        {

        document.body.style.background="red";

                   // document.body.style.color="red";

        }

        else if(val=='green')

        {

    document.body.style.background="green";

        }

              

      }



</script>

</head>


<body>

     

<p id="demo"></p>


<input type="button" onclick="showdttime()" value="finddatetime" />

<input type="button" id="rbtn" onclick="changebackground('red')" value="redbutton"/>

<input type="button" id="gbtn"onclick="changebackground('green')" value="greenbutton"/>

</body>

</html>


Example:5


<html>   

   <head>

      <title>Form Validation</title>      

      <script type = "text/javascript">


       var regex = /ca[kf]e/g;


   var str = "He was eating cake in the cafe.";

   

   var matches = str.match(regex);

   alert(matches.length);


    </script>

    </head>

<body>

</body>

</html>


Example 6:


<!DOCTYPE html>

<html>

<head>

<title>Search Word</title>

</head>

<body>

<script type="text/javascript">


var str = prompt("enter your string");

var srchword=prompt("enter word to search in string");

var copyword=0;


var temp = new Array();

temp = str.split(" ");

alert(temp.length);


for (var i=0;i<temp.length;++i)

{

 if(srchword.match(temp[i]))

 {

copyword=srchword.match(temp[i]);

var pos = temp.indexOf(srchword);

document.write(srchword+" found in your array at "+ pos +" position" );

copyword=-1;

 }

}

if(copyword==0)

{

document.write(srchword+" could not found in your array");

}

</script>


</body>

</html>



Example 7:


<html>  

<head>

  <script>  

  

    if(confirm("do you agree"))

    {

      alert("you have agreed");

    }

     else

     {

          name=prompt("Enter some string here");

          alert("Hi!!" +name);

          document.write("Your Name:"+name);

     }

  </script> 


</head>  

<body>  


</body>  

</html>   


Example:8

<html>  
<head>Factorial No.</head>  
<body>  
<script> 

  var i, no, fact;

fact=1;

no=prompt("Enter your value");

for(i=1; i<=no; i++)  
{
fact= fact*i;
}  

alert("Factorial No.is"+fact);
document.writeln(""+fact);
</script>  
</body>  
</html>   




Example:9


<html>  

<head>Sum of Number</head>  

<body>  

<script>  

  var num,i,sum=0;


  num=parseInt(prompt("Enter Sum of Number"));


    for(i=0;i<=num;i++)

    {

        sum=sum+i;

    }

        alert("Sum of Number" +sum);

        document.writeln(""+sum);

         

</script>  

</body>  

</html>   



Example:10


<html>  

<head>Popup Box</head>  

<body>  

<script>  

  

    var n;

    n=parseInt(prompt("Enter 1st number of addition"));


    if(confirm("second no.is 10"))

    {

        var sum=n+10;

        alert("first"+n+ "second" +sum);

        //document.write(+sum);

    }

</script>  

</body>  

</html>   



Saturday, 14 August 2021

 Java Script

Decision and Looping, Array, Function, Event, Object



Exampe:1

<!DOCTYPE html>

<html>

    <head>   </head>

<body>

    <script>

        var num,k,c;

        var i=1;

        var ch="A";

        var num=10;

       

        for(k=1; k<=num; k++)

        {

         for(c=1; c<=k; c++)

         {

           if(k%2==0)

           {

           document.write(ch++);

           }

           else

           {

           document.write(i++);

           }

         }

         document.writeln("</br");

        }

              

       </script>

</body >

</html>



Exampe:2


<!DOCTYPE html>

<html>

    <head>

        <script>

                function search(myform)

                {

                       var s=myform.fname.value;

                       //var s=document.myform.fname.value;


                       //var s=document.getElementById("demo").myform.fname.value;


                    

                       

                       var n=prompt("enter the word to be search");

                       alert(n);


                       var temp=s.split(" ");


                       for(var i=0;i<temp.length;i++)

                       {

                            if(temp[i]==n)

                            {

                                   alert("the word is at position"+(i+1));

                            }

                       }

                }

            </script>

    </head>

<body>


<form name="myform">

        <input type="text" name="fname" id="fname"></br>

        <input type="button" value="Click me" onclick="search(myform)">

</form>


</body >

</html>



Example:3

 

 <!DOCTYPE html>

<html<head>

<title>JavaScript function</title>

</head>

<body>

<div id="h"></div>

<script>

var v = 0, f = 1,t="Gec Bhavnagar",color;

function a()

{

if(f==1)

v+=5,color="red";

else

v-=5,color="blue";

document.getElementById("h").innerHTML = "<h1 style=\"font-size: "+v+"px ; margin: 0px; color : "+color+"\"><b> "+t+"</b></h1>";

if(v==50)

f = 0, t="Gec Bhavnagar";

if(v==5)

f = 1, t="Gec Bhavnagar";

c();

}

function c()

{

setTimeout(a,300);

}

c();

</script>

</body>

</html>


Example :4


<!DOCTYPE html> 

<html lang="en"> 

<head> 

    <title>JavaScript Event</title> 

</head> 

<body> 


    <h1 id="demo"      onmouseover="mouseOver()"     onmouseout="mouseOut()">    Welcome    </h1> 

    <div class="container"> 

        <p class="Current_Time"></p> 

        <input type="button" value="Time" onclick="time()"> 

    </div> 

    <script>

           function mouseOver() 

        { 

            document.getElementById("demo").style.color="red"; 

        } 

        function mouseOut() 

        { 

            document.getElementById("demo").style.color="black"; 

        } 

        function time() 

       { 

        var date = new Date(); 

        var day = date.getDate(); 

        window.confirm('Are you sure?') 

        document.write(date).style.color="red"; 

       } 

   </script> 

</body> 

</html> 


Example :5


<!DOCTYPE html>

<html>

<head>

<title>Java Script-Event-GECBVN/title>

<script language="JavaScript">

document.write("hello world");

function message(element)

{

alert("You clicked the " + element + " element!");

}

function myFunction() {

alert("hello");

    var x = document.frm.length;

  alert(x);

}

 

</script>

</head>

<body>

<form name="frm">

<input type="radio" name="Radio" onClick="message('Radio Button 1')">Option 1<br>

<input type="radio" name="Radio" onClick="message('Radio Button 2')">Option 2<br>

<input type="checkbox" onClick="message('Check Button')">Check Button<br>

<input type="submit" value="Send" onClick="message('Send Button')">

<input type="reset" value="Reset" onClick="message('Reset Button')">

<input type="button" value="Mine" onClick="message('My very own Button')">

<input type="submit" value="no of ele" onclick="myFunction()" />

</form>

</body>

</html>


Example 6:


<!DOCTYPE html>

<html>

<head>

<title>Java Script-String Method-GECBVN/title>

<script language="JavaScript">

var str=prompt("enter string");

var strlen=str.length;

alert(strlen);

var frstletter = str.charAt(0);

var lastletter = str.charAt(strlen);

alert(frstletter);

if(frstletter=='a' || lastletter=='a' )

            {

                                    document.write("string is in proper format");

            }

 for(var index = 0;index < strlen;index++)

 {

 

            if(str.charAt(index)!='a' && str.charAt(strlen)!='a' )

            {

            var str1 = str.charAt(index);

            alert(str1);

            document.write("<br/>"+str1);

            }

}

</script>

</head>

<body>

</body>

</html>

 


Example 7:

<!DOCTYPE html>

<html>

<head>

<title>Java Script-Event-GECBVN/title>

<script type="text/javascript">

function showdttime()

{

document.getElementById("demo").innerHTML = Date();

}

function changebackground(val)

{

 

            if(val=='red')

            {

                        document.body.style.background="red";

            }

            else if(val=='green')

            {

                        document.body.style.background="green";

            }

}

</script>

</head>

<body>

<p id="demo"></p>

<input type="button" onclick="showdttime()" value="finddatetime" />

<input type="button" id="rbtn" onclick="changebackground('red')" value="redbutton"/>

<input type="button" id="gbtn"onclick="changebackground('green')" value="greenbutton"/>

</body>

</html>


Example 8:

<!DOCTYPE html>

<html>

<head>

<title>Java Script-Event-GECBVN/title>

<script type="text/javascript">

 

window.onkeyup = changebgcolor;

function myKeyPress(e){

 

            var keynum;

 

                           if(window.event){ // IE                                                      

            keynum = e.keyCode;

            }else

                if(e.which){ // Netscape/Firefox/Opera                                                     

                        keynum = e.which;

                 }

                                                 var char1=String.fromCharCode(keynum);

                                                 //for vovel

                                                 if(char1=='a' || char1=="e" || char1=='i' || char1=='o' || char1=='u')

                                                 {

                                                            alert("you have pressed vovel");

                                                 }

            alert("you pressed "+char1 +" & keycode for that is "+ keynum);

}

function changebgcolor()

{

 

document.getElementById("txt1").style.backgroundColor = "blue";

}

</script>

</head>

<body>

<form>

<input type="text" id="txt1" onkeyup="changebgcolor()" onkeypress="myKeyPress(event)"/>

</form>

 </body>

</html>



Example :9


<html>

<head>

<title>Java Script-Date Method-GECBVN/title>

<script type="text/javascript">

var month = parseInt(prompt("enter your birth month (1-12)","") - 1);

 

var day = parseInt(prompt("enter your birth day(1-31)", ""));

 

var birthday = new Date();

var currentdate = new Date();

var one_day=1000*60*60*24;

 

birthday.setDate(day);

birthday.setMonth(month);

birthday = birthday.getTime();

currentdate = currentdate.getTime();

 

var theDate = birthday - currentdate;

document.write(theDate+"<br/>");

theDate = (theDate / one_day);

 

document.write("days left are " + theDate.toFixed(0) + " in your birthday ");

 

</script>

</head>

</html>


Example 10:


<html>

<head>

<title>Java Script-String Method-GECBVN/title>

</head>

<body>

<script type="text/javascript">

var str = prompt("enter string");

var srchword=prompt("enter word to search in string");

var copyword=0;

var temp = new Array();

temp = str.split(" ");

alert(temp.length);

for (var i = 0;i < temp.length; ++i)

{

 if(srchword.match(temp[i]))

 {

            copyword=srchword.match(temp[i]);

            var pos = temp.indexOf(srchword);

            document.write(srchword+" found in your array at "+ pos +" position" );

            copyword=-1;

 }

}

if(copyword==0)

{

            document.write(srchword+" not found in your array");

}

</script>

</body onload=containsAny()>

</html>


Tuesday, 10 August 2021

 Java Script

Array, Function and Objects


Example:1


<!DOCTYPE html>

<html>

    <head>

            <title>JS Fuction arguments  Example</title>

    </head>

<body>


    <script type="text/javascript">


// program to add two numbers using a function

// declaring a function


function add(a, b)

{

  document.write(a+b);

 

}


// calling functions

add(3,8);

add(2,9);


</script>

</body>

</html>



Example:2


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

    </head>

<body>

    <script type="text/javascript">

        var emp=new Object()

    emp.id=101;

    emp.name="james";

    document.write(emp.id+""+emp.name);

    </script>

    </body>

</html>



Example:3

<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

    </head>

<body>


    <script type="text/javascript">

/*

   document.write("</br>"+Number.NEGATIVE_INFINITY);

   


   var temp=new Boolean(false)

   document.write("<br>"+"the value is" +temp.toString());

   // document.write(temp.toString());

    document.write("<br>");


        var s1="hello";

        var s2="peter";


        document.write("first string"+s1+"<br"> "second string"+s2);

        document.write("<br>");


        document.write("output:"+s1.concat(s2)+"<br>");



        document.write("</br>" +Math.floor(2.56));

         document.write("</br>" +Math.max(2,5));

         document.write("</br>" +Math.sqrt(64)); 

         


         var large=Number.MAX_VALUE;

         var small=Number.MIN_VALUE;


         document.write("<br> the largest number is"+ large.toString(2));

         document.write("<br> the smallest number is"+ small.toString(8));



         var num=Number(15);


         document.write("<br> the largest number is"+ num.toString(2));

         document.write("<br> the smallest number is"+ num.toString(3));


         //var n=new Number(45);

         //var Number=number_value;



        var currdate=new Date();

        //currdate=currdate.toString();

        //document.write("<br>"+currdate);

        document.write("<br>"+currdate.getDate());



        var mydate=new Date("1 jan 2021");

        currdate.setDate(25);

        document.write("<br>"+currdate);


          var string1,string2;

          string1=" IT Department " ;

          string2=" GECBVN ";


          string3=string1+""+string2;


          document.write("<br>"+string3);


*/

          var string1=new String("GECBVN");

          var string2="GECBVN";


         var a="hello world";

         document.write("<br>"+a.substr(2,2));



         var mystr="hello";

         var len;


         len=mystr.length;

        document.write("<br>" +len);


        s1="department";

        s2="DEPARTMENT";


        document.write("output" +s1.toUpperCase()+"<br>");

        document.write("output" +s2.toLowerCase()+"<br>");



        document.write(Math.min(4,5,6,7)+"<br>");

        document.write(Math.sqrt(4)+"<br>");

        document.write(Math.pow(4,2)+"<br>");


              var mydate=new Date();

              document.write("the date is " +mydate.toString()+"</br>")

              document.write("the date is " +mydate.getDate()+"</br>")

              document.write("the date is " +mydate.getMonth()+"</br>")

              document.write("the date is " +mydate.getTime()+"</br>")

              document.write("the date is " +mydate.getHours()+"</br>")

              document.write("the date is " +mydate.getMinutes()+"</br>")

              document.write("the date is " +mydate.getSeconds()+"</br>")



            alert("Welcome");

/*

          var b="Department";

          document.write(b.charAt(2));


         var str,result;

         str="javascript";

         result=str.search("script");

         document.write("<br>"+result);


         


         var var1= 1 +'2';


         document.write("</br>" +typeof(var1));



         document.write("</br>" + var1);

         document.write("</br>" + Math.sin("12.45"));


        var bestpalces= new Array(5);

        bestpalces[0]="Bhavnagar";

        bestpalces[1]="Gandhinagar";

        bestpalces[2]="Patan";

        bestpalces[3]="Surat";

        bestpalces[4]="Rajkot";


        //bestpalces.push("Aanand");

        bestpalces.pop("Rajkot");


        document.write("</br>"+bestpalces.pop());


        for(i=0;i<bestpalces.length;i++)

        {

        document.write("</br>" +bestpalces[i]);

   

        }*/

   </script>


        </body>

</html>



Example:4

<!DOCTYPE html>

<html>

    <head>

            <title>JS Function Example</title>

            <script type="text/javascript">



                /* How to Create a Function in JavaScript

                Use the keyword function followed by the name of the function.

                After the function name, open and close parentheses.

                After parenthesis, open and close curly braces.

                Within curly braces, write your lines of code.*/

                

                function demo(str1,str2)

                {

                        str="function is"+ str1+""+str2;

                        return str;

                

                }

                

                </script>

    </head>

<body>


    <script>

    document.write("<h2>" +demo("hello","How are you!")+"</h2>");

        </script>

</body>

</html>



Example:5


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

    </head>

<body>


    <script type="text/javascript">


//Function with Arguments

//You can create functions with arguments as well. Arguments should be specified within parenthesis

var count = 0;

function countVowels(name)

{

for (var i=0;i<name.length;i++)

{

              if(name[i] == "a" || name[i] == "e" || name[i] == "i" || name[i] == "o" || name[i] == "u")

              count = count + 1;

}

document.write("Hello " + name + "!!! Your name has " + count + " vowels.");

}

    var myName = prompt("Please enter your name");

    countVowels(myName);


        </script>


        </body>

</html>


Saturday, 7 August 2021

Java Script-Basic

Data types, Conditions, Loops

Example:1


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

                <script type="text/javascript">

               /*        

                document.getElementById("demo").innerHTML = "My First JavaScript";*/             

                document.writeln("Hello");

             var a=10; b=20;

             var total=a+b;

             document.writeln("Addition of two number" +total);

                         </script>

    </head>

<body>  

</body>

</html> 



Example:2


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


                <script type="text/javascript">


                //document.getElementById("demo").innerHTML = "My First JavaScript";

                document.writeln("Hello"+"</br>");

                document.writeln("Hello"+"</br>");

                document.writeln("Hello"+"</br>");


                var myobj;

                myobj=new Date();                          

                myobj1=null;


                document.write("myobj=" +typeof(myobj1)+"</br>");

                var mynumber;

                //var str="IT";

                

                document.write("mynumber=" +typeof(mynumber)+"</br>");


                        var a=10;

                        var b="hello";


                        c=a*b;


                        document.write(c);


                                        document.write("<br/>"+"output:"+parseInt("12pqr"));

                                        document.write("<br/>"+"output:"+parseFloat("12.20pqr"));

                                        var w=2;

                                        var str1;


                                        str1=w.toString();


                                        document.write("<h1>"+str1);

                </script>

    </head>

<body>

</body>

</html> 


Example:3


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


                <script type="text/javascript">


                 var a=5;

                                  

                 if(a%2==0)

                 {

                    document.writeln("a is EVEN no.");

                 }

                 else

                 {

                    document.writeln("a is ODD no.");


                 }

              </script>

    </head>

<body>

    

</body>

</html>


Example:4


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


                <script type="text/javascript">


               var a=40,b=30,c=20;

               

               if(a>b)

               {

                  if(a>c)

                  {

                     document.writeln("A is larger number");

                  }

                  else

                  {

                     document.writeln("C is larger number");

                  }

               }


               else

               {

                     if(b>c)

                     {


                        document.writeln("B is larger number");

                     }

                     else

                     {

                        document.writeln("C is larger number");


                     }

               }

 

        </script>

    </head>

<body>

   

</body>

</html>


Example:5


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


                <script type="text/javascript">


                  var grade='b',result;

                  switch(grade)

                  {

                         case 'a':

                         result="A-Grade";

                         document.writeln("result" +result);

                         break;


                         case 'b':

                         result="B-Grade";

                         document.writeln(result);

                         break;



                         case 'c':

                         result="C-Grade";

                         document.writeln(result);

                         break;


                         default:

                         document.writeln("No result");


                  }


               </script>

    </head>

<body>

   

</body>

</html> 


Example:6


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

    </head>

<body>


    <table border="1" align="center">

    <script type="text/javascript">

        {


            do

            {

                var i=1;

                document.writeln("<tr><td>" +i+"</td><td>" +(i*i)+"</td></tr>" );

                i++;

            }

            while(i<=10);

        }

 </script>

</table>

</body>

</html> 


Example:7


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


            

               

    </head>

<body>


    <table border="1" align="center">

    <script type="text/javascript">

        {

            var i=1;

            for(i=1;i<=10;i++)

            {

                document.writeln("<tr><td>" +i+"</td><td>" +(i*i)+"</td></tr>");

            }

            

        }

        

        


       </script>


</table>

</body>

</html> 


Example:8


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>


            

               

    </head>

<body>


    <table border="1" align="center">

    <script type="text/javascript">

        {

            var i=1,a;

            for(i=1;i<=10;i++)

            {


                if(i==5)

                {

                a=i;

                continue;    

                }

                document.writeln("<tr><td>" +i+"</td><td>" +(i*i)+"</td></tr>"); 

            }

             

        }

        document.writeln("<tr><td>" +a+"</td><td>"+"</td></tr>");

        


       </script>


</table>

</body>

</html> 


Example:9


<!DOCTYPE html>

<html>

    <head>

            <title>JS Example</title>

    </head>

<body>


    <script type="text/javascript">


            var num=5,n1=0,n2=1,i,sum;


            for(i=1;i<=num;i++)

            {


                document.writeln(n1);


                sum=n1+n2;

                n1=n2;

                n2=sum;

    

            }

        </script>


        </body>

</html>


Example:10


<html>

<head></head>

<title></title>

<body>

<script>


var i,sum = 0;


for (i = 1; i <= 10; i =i+2)

{

    document.writeln(i+"</br>");

    sum =sum+ i;

}

    document.write("sum of number"+sum);

</script>

</body>

</html>


Example:11


<!DOCTYPE html>

<html>

        <head>

            <title>JS Example</title>

     

        </head>

<body>


<script type="text/javascript">


var i,j;

for(i=2;i<=30;i++)

{

for(j=2;j<I;j++)

{

if(i%j==0)

{

break;

}

}

If(i==j)

{

Document.wite(i+”<br>”);

}

}

    

</script>

</body>

</html> 



Example:12


<html>

<head></head>

<title></title>

<body>

<script>

    

var sum=0,n=10;

while(n>=1)

{

sum=sum+n;

n=n-1;

}

document.write("sum of number"+sum);

</script>

</body>

</html>