0

Need writing a java script that will list prime numbers from 1 - 999
in a 10 Row table...I think I have the prime number logic part down but I cant figure out how to get JS to start a new column after it lists 10 numbers? I would obviously need a counter variable to count from 1 to 10 each time the loop is executed positive for a prime number then reset at 10 but I cannot figure out how. Any help would be appreciated

Sorry if this isn't the right section of the forum I didnt see anything for Java script

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by madmital
0
var rowCounter = 0;
var columnCounter = 0;
for(var i = 0, len = 999; i < len; i++) {
	if(some prime number logic returns true) {
		rowCounter++; // increment row counter
		if(rowCounter >= 10) { // if ten rows have been written
			rowCounter = 0; // reset row counter
			columnCounter++; // next column
		}
		
		/*
			output number to table.row[rowCounter].column[columnCounter]  assuming table, rows and columns already exist
		*/
	}
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.