seulki
12-14-2010, 09:09 AM
I'm kind of stumped at how to fix this, but here is what i have so far ^^
// <==things displayed after this is what i have to do.
I was wondering if there was a better way to reword it :x or if i'm missing something >.<;
Thank you.
<html>
<!-- IsPrime.html -->
<!-- This page determines if a given positive integers is a Prime number. -->
<!-- =================================================== -->
<head>
<title> IsPrime </title>
<script type="text/javascript"
src="http://dave-reed.com/book/random.js">
</script>
<script type="text/javascript">
function IsPrime()
// Assumes: IntBox contains a positive integer
// Results: Uses the IntBox value to determine if it is a Prime number
// (A Prime number IS ONLY EVENLY DIVISIBLE(remainder of 0) BY 1 and ITSELF)
// and displaying the result in the 'PrimeBox' as either TRUE or FALSE
// Example: IntBox = 7, then PrimeBox = TRUE
// Example: IntBox = 8, then PrimeBox = FALSE
// Algorithm:
// 'dividend' starts with a value of 2 and 'isprime' starts with a value of 'true'
// DO: get the remainder of dividing the number by the current value of the dividend
// IF the remainder is even, then set isprime to false
// ELSE increment the dividend by one
// WHILE (the dividend is less than the number AND isprime is true)
{
var dividend, isprime, number;
dividend = 2;
isprime = true;
number = Math.sqrt(document.getElementById("IntBox").value);
number = parseFloat(number);
do {
remainder = number/dividend;
if ((remainder % dividend) == 0) {
isprime = false;
document.getElementById("PrimeBox").value = "False";
}
else {
dividend = dividend + 1;
}
}
while (dividend < number && isprime = true) {
document.getElementById("PrimeBox").value = "True";
}
}
</script>
</head>
<body>
<div style="text-align:center">
<h2>Prime number determination</h2>
<p>
Enter a positive integer =
<input type="text" id="IntBox" size="6" value="1" />
</p>
<p>
<input type="button" value="Click here to determine if number Is Prime" onclick="IsPrime();" />
</p>
<p>
Results =
<input type="text" id="PrimeBox" size="15" value="MAYBE..." />
</p>
</div>
</body>
</html>
// <==things displayed after this is what i have to do.
I was wondering if there was a better way to reword it :x or if i'm missing something >.<;
Thank you.
<html>
<!-- IsPrime.html -->
<!-- This page determines if a given positive integers is a Prime number. -->
<!-- =================================================== -->
<head>
<title> IsPrime </title>
<script type="text/javascript"
src="http://dave-reed.com/book/random.js">
</script>
<script type="text/javascript">
function IsPrime()
// Assumes: IntBox contains a positive integer
// Results: Uses the IntBox value to determine if it is a Prime number
// (A Prime number IS ONLY EVENLY DIVISIBLE(remainder of 0) BY 1 and ITSELF)
// and displaying the result in the 'PrimeBox' as either TRUE or FALSE
// Example: IntBox = 7, then PrimeBox = TRUE
// Example: IntBox = 8, then PrimeBox = FALSE
// Algorithm:
// 'dividend' starts with a value of 2 and 'isprime' starts with a value of 'true'
// DO: get the remainder of dividing the number by the current value of the dividend
// IF the remainder is even, then set isprime to false
// ELSE increment the dividend by one
// WHILE (the dividend is less than the number AND isprime is true)
{
var dividend, isprime, number;
dividend = 2;
isprime = true;
number = Math.sqrt(document.getElementById("IntBox").value);
number = parseFloat(number);
do {
remainder = number/dividend;
if ((remainder % dividend) == 0) {
isprime = false;
document.getElementById("PrimeBox").value = "False";
}
else {
dividend = dividend + 1;
}
}
while (dividend < number && isprime = true) {
document.getElementById("PrimeBox").value = "True";
}
}
</script>
</head>
<body>
<div style="text-align:center">
<h2>Prime number determination</h2>
<p>
Enter a positive integer =
<input type="text" id="IntBox" size="6" value="1" />
</p>
<p>
<input type="button" value="Click here to determine if number Is Prime" onclick="IsPrime();" />
</p>
<p>
Results =
<input type="text" id="PrimeBox" size="15" value="MAYBE..." />
</p>
</div>
</body>
</html>