Showing posts with label Java Script Program. Show all posts
Showing posts with label Java Script Program. Show all posts
Thursday, 24 July 2014
Tuesday, 22 July 2014
Find Prime No. Using Java Script
Find Prime No. Using Java Script
Java script has very simple code for browser. Generally java script is used to restrict user. But you can learn java script by playing with coding.
Program:
var num =prompt("Enter a number");
parseInt(num);var i;var b=0; if(num==1)
{
alert("A prime number is a number which has only two factors, 1, and itself. But in the case of 1, there is only one factor: 1. So, 1 is not a prime number");
}
else{
for(i=1;i<=num;i++)
{
var result = num%i;
if(result==0)
{
b++;
} }
if(b<=2)
{
alert("Prime no.");
}
else
{
alert("Not Prime");
}
}
Wednesday, 16 October 2013
Hide Div tag By-Tanuj Kumar
Javascript Code to Show or Hide Div:
This function can be done easily by java script program .
<html>
<head>
<title>Javascript Program to Show/Hide Div Visibility</title>
<script language="javascript" type="text/javascript">
function showHideDiv() {
var divstyle = new String();
divstyle = document.getElementById("div1" ).style.visibility;
if (divstyle.toLowerCase() == "visible" || divstyle == "") {
document.getElementById("div1" ).style.visibility = "hidden";
}
else {
document.getElementById("div1" ).style.visibility = "visible";
}
}
</script>
</head>
<body>
<div id="div1" class="divStyle">
Show/Hide Div tag using java script.
</div>
<center>
<input type="button"
value="show hide div"
onclick="showHideDiv()" />
</center>
</body>
</html>
Posted By:Tanuj Kumar
On:Shareyourconscience
Tuesday, 1 October 2013
Find Prime No. Using Java Script By:Tanuj Kumar
Find Prime No. Using Java Script
var num =prompt("Enter a number");
parseInt(num);var i;var b=0; if(num==1)
{
alert("A prime number is a number which has only two factors, 1, and itself. But in the case of 1, there is only one factor: 1. So, 1 is not a prime number");
}
else{
for(i=1;i<=num;i++)
{
var result = num%i;
if(result==0)
{
b++;
} }
if(b<=2)
{
alert("Prime no.");
}
else
{
alert("Not Prime");
}
}
Posted By:Tanuj Kumar
On:Shareyourconscience
Subscribe to:
Posts (Atom)
