Skip to main content

Java Script Part 1

Hi,
I had planned to create java script tutorials for students and readers of my blog. here I will discuss very important points regarding java script.

I will keep updating this post so readers are advised to visit it frequently.

I would also like to share some important javascripts as below.

1. javascript to find first 10 prime numbers.


<html><head>
       <title>first 10 prime numbers </title>
</head>
<body>

<script type="text/javascript">
 
 var count=10,i=0,j=0,k=2;
 document.write("<br/><h2>first 10 prime numbers.</h2>");
 for(i=0;i<count;k++)
 {
        var isprime = true;
     for(j=2;j<=k-1;j++)
     {
              if(k%j == 0){
        isprime = false;
        break;
     }
     
     }
     if(isprime == true){
        document.write("<br/> prime no : "+k);
     i++;
     }
 }

</script>
</body>
</html>


output of the script is as below.


------------------------------------------------------------------------------------------------------------------------
2. Javascript to check if string is palindrome or not




<html>
<head>
       <title>javascript to check if string is palindrome or not ?</title>
</head>
<body>

<script type="text/javascript">
    var s1,s2,len,i,ispalindrome=true;
 s1= prompt("would you please enter string");
 len = s1.length;
    
 document.write("<br/><h2>you have entered "+ s1 +"</h2>");
 
 for(i=0;i<len;i++){
  if(s1[i] != s1[len-1-i]){
    ispalindrome = false;
    break;   
  }
 }
 if(ispalindrome == true )
 {
    document.write("<br/><h2>entered string "+ s1 +" is palindrome</h2>");
 }
 else
 {
    document.write("<br/><h2>entered string "+ s1 +" is NOT palindrome</h2>"); 
 }
</script>
</body>
</html>



output of the script is as below. IT WILL ASK FOR STRING

AND WILL SHOW ANSWER AS BELOW.


Comments

Popular posts from this blog

PHPMOTION JW Player SD/HD Integration.

jw player is really a great video player.it contains great features like it allows users to choose from SD/HD video. so user may play video as per his/her internet speed. in this post i am going to show how its possible to integrate jw player with its SD/HD options with phpmotion video script.

PHPMOTION VIDEOJS PLAYER INTEGRATION

videojs is the open source HTML5 video player. today we are going to see how videojs player can be integrated with phpmotion video script. some popular sites using videojs are  http://twitpic.com/  ,  http://telly.com/  ,  http://vine.co/  ,  http://www.theonion.com/  , http://web.mit.edu/   ,  https://www.airbnb.com/?cdn_locale_redirect=1

PHPMOTION JW Player Integration

phpmotion  is a popular video script.by default phpmotion uses flash player to show/play videos at home page as well as video play page.The JW Player is the Internet's most advanced and flexible media player. in this tutorial I am going to show how it is really easy to do phpmotion jw player integration.