Displaying First 1000 Prime Numbers In Table

Jan 27, 2009

I am taking a javascript class and I need a script that displays the first 1000 prime numbers in a table with 10 numbers per row. I've been trying on my own for about 4 hours now and am really confused. I just started the class and have only started learning javascript 3 days ago.

View 6 Replies


ADVERTISEMENT

Displaying List Of Prime Numbers Only

Jun 23, 2011

So I wrote this piece of code, which should display the first 10,001 prime numbers.
Code:
<html><head>
<title>Problem 7 project euler</title>
</head><body><script>
var x = 3;
var primes = new Array();
primes[1] = 2;
var n = 1;
document.write("PRIME#1= 2" + "<br />")
while (n < 10001){
if (x%primes[n] == 0){
x = x + 2;
}else if ((n + 1) < (primes.length)){
n = n + 1
}else{
primes[(n+1)] = x;
document.write("PRIME#" + (n + 1) + "= " + primes[(n+1)] + "<br />");
x = x + 2;
n = 1
}}
</script>
</body>
</html>
Now the problem is that somehow this code also interprets some non-primes as primes.

View 7 Replies View Related

Writing Prime Numbers To Table

Jan 26, 2011

I can't seem to get past my function writing
<table rows='10 cols='10' border='1'><tr><th>Prime Numbers(1-100)</th></tr>
<!DOCTYPE HTML PUBLIC "-W3CDTD HTML 4.01EN" "[URL]">
<html>
<head>
<script type="text/javascript">
function primeNumbers() {
var tableCell = 0;
document.write("<table cols='10' border='1'>");
document.write("<tr>"); .....

View 4 Replies View Related

JQuery :: Add Row Numbers To A Table?

Nov 4, 2011

I thought this would be fairly easy, but I've searched and searched and came up with nothing that works. I just need to add row numbers to my table. I already have the first column blank, I just need the row numbers stuck in there. I've found examples using .index() and .rowindex, but I can't find anything that works right.

View 5 Replies View Related

Prime Or Not.

Apr 8, 2006

I'm not too experienced in programming, all I know is from practicing so don't be surprised if I made some mistakes. One mistake that I know is that the page is absolutely non-standard, but I don't really care about things like web-standards when making these little scripts.
As I'm Hungarian and not English, this code (functions, vars) was also written in Hungarian, but I translated it to be a bit more readable for Englishpeople. If it's still not clear, I can comment it.

<style>
body{text-align:center; font-family:arial;}
.answerbox,.detailbox {
background-color:#FFFFFF;
font-size:80;
height:100;
color: black;
font-weight:bold;
text-align: center;
width:950;
}

.detailbox {
height:80;
font-size:50
}

sup {font-size:40; vertical-align:top; position:relative; top:-5}

#quest{
font-size:20;
text-align:right;
border-style: solid;
border-color: gray;
border-width: 1;
width: 130
}
</style>
<script>

function power(arr)
{
newarr=new Array()
for(k=0; true; k++)
{
base=arr[0]
for (expo=1; arr[expo]==base;expo++){}
newarr[k]=base+(expo!=1 ? "<sup>"+expo+"</sup>" : "")
if (expo>=arr.length) {break}
arr=arr.slice(expo)
}
return newarr.join("×")
}

function twodivisors(numb)
{
for (var i=2; i<=Math.sqrt(numb); i+=1)
{
if (numb%i==0) {return new Array(i,numb/i)}
}
return "pr"
}

function analyze(num)
{
iffalse=detailsplace+"=num+'='+power(primedivisors);"+yesnoplace+"='Number '+num+' is not prime'"
iftrue=yesnoplace+"='Number '+num+' is prime'"+detailsplace+"=''"

if (num<2) {eval(detailsplace+"=''"+yesnoplace+"='Number '+num+' is not prime'"); return}
if (num==2) {eval(iftrue); return}

if (num%2==0)
{
primedivisors=new Array()
primedivisors.push(2)
for (otherdivisor=num/2; twodivisors(otherdivisor)!="pr"; otherdivisor=twoparts[1])
{
twoparts=twodivisors(otherdivisor);
primedivisors.push(twoparts[0]);
}
primedivisors.push(otherdivisor)
eval(iffalse); return
}

for (var i=3; i<=Math.sqrt(num); i+=2)
{
if (num%i==0)
{
primedivisors=new Array()
primedivisors.push(i)
for (otherdivisor=num/i; twodivisors(otherdivisor)!="pr"; otherdivisor=twoparts[1])
{
twoparts=twodivisors(otherdivisor);
primedivisors.push(twoparts[0]);
}
primedivisors.push(otherdivisor)
eval(iffalse); return
}
}
eval(iftrue); return
}

function starter()
{
num=document.formh.quest.value
if (isNaN(num)) {alert("You entered an invalid number."); return}
detailsplace="document.getElementById('details').innerHTML"
yesnoplace="document.getElementById('answer').innerHTML"
analyze(eval(num))
}

</script>

<div class=answerbox id=answer></div>
<div class=detailbox id=details></div>
<form name=formh>
Number: <input type=text id=quest><br>
<input type=button value="Is it prime?" onClick=starter()><br>
</form>

View 2 Replies View Related

Dynamically Re-generate Random Numbers In A Table?

Nov 19, 2009

I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.[code]...

View 1 Replies View Related

How To Dynamically Re-generate Random Numbers In A Table

Nov 19, 2009

I have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads.code...

View 1 Replies View Related

Displaying A Table With Inner HTML

May 5, 2007

My program builds several tables using inner HTML. All the tables are displayed only when the program terminates. How can I make it display one table at a time and then wait for a click before displaying the next table?

View 9 Replies View Related

Displaying A Table In Firefox Or IE?

Sep 30, 2010

Wasn't sure if I should post this in the CSS or Javascript section so I just went with Javascript as it's what the code is in. Made a small Javascript game, when the player looses it will populate a table which is set to display: none; with the scores and then using the code below show the table...

document.getElementById('scoresTable').style.display = 'table'; This works fine for me in Opera, Google Chrome and Safari .. but not Firefox or IE.

View 11 Replies View Related

Displaying Value From Table Row And Column?

Jan 31, 2009

How can the user obtain a specific result by choosing values from 2 dropdown list. As a result, the value obtained can not be modified by the user. The table of ten rows by ten columns have to be stored in a mysql dbase.. It's certanly possible , but tedious and time-consuming by using a bunch of "if ... then statements". Considered from a table point of view, the final result is the coordinate of a row value and a column value.

View 1 Replies View Related

JQuery :: Displaying And Hiding A Specific Row In The Table?

Jul 23, 2011

When you click the text "info" in the column "comments", a row should be displayed below with text information that is related to the "comments". Need also to click the text "Info" again to hide the text information of comments. Problem: I don't know how to display the row when you click one of the comments with the text "info". When clicking one of the link the remaining rows with the text "info" should not be affected. In order words, the part should be independent Need also some help hiding the text information of comments.

There are some things that you also need to take account to: - The amount of data that will be displayed in the table will be changed from day to day. The data is taken from a xml file.- Would like the sourcode to be written in jQuery.- Only html, css and javascript is allowed in this context.- html code in tr and td will be generated by javscript code.The class "firstDataRow" is the added in the tr row that has the text information of commentsPlease remember that the text hide and show is only for temporary.

// Fullmetalboy
<table border="1" SUMMARY="aaa" id="tblProject">
<thead>

[code]....

View 4 Replies View Related

JQuery :: MySQL And Displaying Results In Table?

Feb 17, 2011

I want to do is let the user input a file,then read the contents send it to the server, loop over the inputs to query MySQL, return the results and display it in a user friendly,scrollable table?

View 1 Replies View Related

Displaying The Fetched Data From Db On MouseOver In A Table

Jul 26, 2010

I have a code that will fetch out the data from database OnMouseOver. But it is working fine if don't add table on the div which will come OnMouseOver. If i try to show the fetched data in table then the code doesn't work. Here is my code:

<script type="text/javascript" language="JavaScript">
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
[Code]....

View 3 Replies View Related

Displaying An Associative Array Into An Html Table?

Mar 19, 2011

am just trying to learn javascript and my friend gave me a little assignment to try and figure out. i am having trouble figuring it outbasically i just want to display the information in my associative array, into an html table.

var NFC_east = new Array();
NFC_east[0]=["Giants", 16, 0, "Eli Manning"];
NFC_east[1]=["Cowboys", 0, 16, "Tony Romo"];

[code]....

View 1 Replies View Related

Displaying Extra Information Under A Row (in A Table) On Rollover.

May 19, 2006

When a user rolls over a table entry (row) extra information needs to be displayed under that particular row. What's the best way to do this?

I was thinking puting a div under each row and adding a css style to make each hidden. Then on rollover the style would be set to visible.

Are there any other ways of doing this? Printing a div under each row seems rather inefficient.

View 2 Replies View Related

Difficulty In Displaying Checkbox Value Into Table Cell?

Jul 26, 2010

I wanted to retrieve the checkbox value and display each value in each column of the table.Here's the code.

Code:
<html>
<head>

[code]....

View 6 Replies View Related

Firefox Giving DOM Security Error 1000

May 10, 2010

Firefox is throwing a DOM security error. I've used toDataURL() before, and it's never done this. I need to get this little app fixed, so that I can use it on my TabletPC for taking notes in class. The line of code that is throwing this error is:
var Note = document.getElementById("SketchPage").toDataURL();

Here's the full error from the Error Console:
Error: uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "file:///C:/SketchBook-Dev/SketchBook.js Line: 236"]

Here is the JS file:
var PenSize = "3";
var PenShape = "Circle";
var PenColor = "Black";
var LoadFile = "";
var UIstatus = "visible";
var CurrentNote = 0;
var BGcolor = "#C7C1A3";
var DataPath = "Data\";
var ImageExtension = ".img";
var FileList = [];
var SystemPath;
var UIstatus = "visible";
var Server = "localhost";
var NxtNote = new Image();
document.onkeyup = ToggleUI;
function Init() { .....

View 1 Replies View Related

Make The Amount Entered In A Text Box Not Greater Than 1000?

Apr 15, 2010

how do we use javascript to make the amount entered in a text box not greater than 1000?

View 1 Replies View Related

Limit The Numeric Amount Entered In A Text Box Less Than 1000?

Apr 15, 2010

how do I use javascript to limit the numeric amount entered in a text box less than 1000?

View 1 Replies View Related

Adding Table Rows - Putting In A Dropdown Box That Contains Numbers That Will Dynamically Show The Rows

May 1, 2009

i'm creating a ASP page, which is going to have a form in it that needs filling out. part of the form will be a table with a header row, then the next rows will have text boxes that need filling out. is there a way of putting in a dropdown box that contatins numbers that will dynamically show the rows. for example if i select 5, then five rows of text boxes will appear. if i select 14 then 14 appear.

View 3 Replies View Related

ExtJS Capable Of Handling Grids/Datastors Of ~1000 Elements?

Jul 15, 2009

I have a JavaScript application which opens an ExtJS Window, containing an ExtJS TabPanel, which has a tab containing a Data Grid, showing approximately 900 - 1000 rows, each with 7 columns of text fields. The grid may also be filtered to show about 100 rows at a time. When the window opens, navigating to this tab can cause Firefox or Safari to spin/lock up for over 60 seconds...

This is Ext 2.2 I know it's very hard to say without code... but without seeing code, my question is: Should ExtJS be capable of displaying a grid of so much data? In trying to optimize should I be looking at my code, or is ExtJS itself the problem? Is anyone using ExtJs to display such large grids?

View 4 Replies View Related

Generates A Random Number Between 1-1000 And Then Allows The User To Make Guesses In A Text Box

Apr 15, 2010

I'm having to write a program that generates a random number between 1-1000 and then allows the user to make guesses in a text box, answering to high or to low, until the correct answer is entered. I had the program working fine with using strictly prompts and alerts but when I tried to create a form I started having trouble.

<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>9.30</title>
[Code]...

View 3 Replies View Related

JQuery :: Install On IE7 - 1000+ Workstations - Users Accessing The Site From A Very Slow Network

Feb 4, 2011

I am about to launch a SharePoint site with thousands of users accessing the site from a very, very slow network. Two questions. Is there a way to 'install' jquery so that it doesn't download every time they access the site?

_All_ users are on the same domain and are using IE7. Once they download JQuery on the initial page visit, does it still redownload the file every time they access the site? Temporary internet files don't get cleared after each session, so I'm assuming it doesn't get re-downloaded.

View 2 Replies View Related

"speed Up" Prime # Test Script With These Modifi?

Nov 15, 2011

I have this code for figuring out whether a given number is prime or not:

var SMALLEST = 2;
var BIGGEST = 9E15;
var n = prompt("Enter a number and I'll check if it is prime");
if (isNaN(n) || n < SMALLEST || n > BIGGEST || n % 1 !== 0) {
alert("I can only test integers between " + SMALLEST + " and " + BIGGEST);

[Code]...

View 2 Replies View Related

Include Numbers And Alphabets Instead Of Numbers Only?

Apr 7, 2009

I need to modify the script showed at: [URL]

Right now it allows entering "numbers only", I need it so that it allows numbers and alphabets only, no special characters or spaces.

And yes, one more question, does the first part of the code need to be added in the <head> of the document or <body> ?

The code at the above URL is as follows:

<script type="text/javascript">
// initialise variable to save cc input string
var cc_number_saved = "";
</script>

[Code].....

View 2 Replies View Related

Adding 1000 Days To A Date Result A Full (date) "mm/dd/yyy"

Aug 17, 2011

I'm trying to get a full date. In this script I want the user to be able to enter a date and get a 1000 day result a full (date) mm/dd/yyy. So far this give me the year only. I've tried so many ways.

<script language="javascript">
var reply = prompt("Please enter the date you and your love begin dating (mm/dd/yyyy)", " ");
var newstring = new String(reply);
var arrTemp = new Array();
arrTemp = newstring.split("/");
[Code]....

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved