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.
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>
AND WILL SHOW ANSWER AS BELOW.
Comments
Post a Comment
Hi, Thanks for the comment will try to reply at the earliest.
Good Day,
Hiren Patel
http://www.renruhak.org