Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, August 31, 2010

JAVASCRIPT Problems

Hello


Students check these javascript problems

  1. Add new elemts at the beginning of array
    <html >
    <body >
    <script language="javascript" >
    var scripts=new Array();
    scripts[0]="PHP";
    scripts[1]="ASP";
    scripts[2]="JAVASCRIPT";
    scripts[3]="HTML";
    document.write(scripts.join("< br > "));
    document.write("< br >---- NOW AFTER APPLYING unshift()---< br >");
    scripts.unshift("VBSCRIPT","PERL");
    document.write(scripts.join("< br >"));
    </script >
    </body >
    </html >

  2. Display Today's date and Time

    < html >
    < title >
    < /title >
    < body >
    < script language="javascript" >
    var d=new Date;
    document.write("< b > "+d);
    < /script >
    < /body >
    < /html >
  3. Add an element to position 2 in an array
    < html >
    < body >
    < script type="text/javascript" >
    var fruits = ["HTML", "JSP", "PHP", "ASP"];
    document.write("Removed: " + fruits.splice(2,0,"JAVASCRIPT") + "< br / >");
    document.write(fruits);
    < /script >
    < /body >
    < /html >

  4. Concatenate two arrays

    < html >
    < body >
    < h2 > concat arrays containig alphabets,numbers,symbols < /h2 >
    <script language="javascript" >
    var alphabets = ["a","b","c"];
    var numbers = ["1","2"];
    var symbols = ["@", "$","^"];
    var alphano = alphabets.concat(numbers,symbols);
    document.write(alphano);
    < /script >
    < /body >
    < /html >

  5. To concert today's date to string
    < html >
    < body >
    < script language="javascript" >
    var d =new Date();
    document.write("in original form");
    document.write(d +"< br/ > ");
    document.write("(according to UTC) to string:");
    document.write(d.toUTCString());
    < /script >
    < /body >
    < /html >

  6. TO remove first element of the array
    < html >
    < head >
    < title > Removing the first Element < /title >
    < script language="javascript" type="text/javascript" >
    < !--
    var x = new Array(1,2,3,4);
    var firstElement = x.shift();
    alert(firstElement);
    alert(2);
    alert(3);
    alert(4);
    alert(x);
    //-->
    < /script >
    < /head >
    < body >
    < h1 > Removing the first Element < /h1 >
    < /body >
    < /html >

  7. Replace character in a string
    < html>
    < body>
    < script language="javascript" >
    var str="LOGIN UR ID!";
    document.write(str.replace(/ID/,"ACCOUNT"));
    < /script >
    < /body >
    < /html >
  8. Reverse order of elements in the array
    < html >
    < title > JavaScript array reverse() example < /title >
    < body >
    < h2 >
    Example of reversing an array
    < /h2 >
    < script type="text/javascript" >
    var arr = new Array(3);
    arr[0]="1";
    arr[1]="2";
    arr[2]="3";
    document.write("< b > Array before reversed is < /b >="+arr+"< br > ");
    document.write("< b > Reversed array is < /b > ="+arr.reverse()+"<br > ");
    < /script >
    < /body >
    < /html >

compiled by PRAPTI