How do I get this to count from the "startnumber" I chose to the "endnumber" I chose? I got it to count from 1 to the end number, but I don't know how to get it to print from the number I choose like 4 to 10.

<HTML>

  <head>
     <title>
      Java Assignment 3
     </title>
  </head>


  <body>
   
  <BODY BGCOLOR=black text=white>

	<script type="text/javascript">

	var name;
	var startnumber;
	var endnumber;
	var count;

	count=0;
 
	name=prompt("Please enter your name", "");
	document.write("Hello ", name,"<br>");

	startnumber=prompt("Which number would you like to start with?", "");
	document.write("Starting number: ", startnumber, "<br>");

	endnumber=prompt("Which number would you like to end on?", "");
	document.write("Ending number: ", endnumber, "<br>");
	

	while (count!=endnumber)
		{
		count=count+1;
		document.write(count, "<BR>");
		}

</body>
</html>

   </script>

You're in the wrong forum. And generally, a for loop is better for iteration than a while loop is if you know what values you want to iterate over.

If you're referring about javascript and not JAVA. Then you can do the following format to achieved this issue.

<?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" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Test Page</title>
</head>
<body>
<div id="main">
<script type="text/javascript">
// <![CDATA[
var name, startNumber, endNumber, counter;

   counter = [];
   name = prompt("Please enter your name", "");

   document.write("Hello , " + name.fontcolor("green").bold().toUpperCase() + "!<br />\n" );
   startNumber = prompt("Which number would you like to start with?", "");
   document.write("Starting number: " + startNumber.bold() + "<br />\n" ); 
   counter[0] = startNumber;
   endNumber = prompt("Which number would you like to end on?", "");
   document.write("Ending number: " + endNumber.bold() + "<br />\n" ); 
   counter[1] = endNumber;
   document.write( "<p>" )
   for ( var x = counter[0]; x <= counter[1]; x++ ) {
    document.write( x + " &#8212; " );
 } document.write( "&gt;</p>\n" );

// ]]>
</script>
</div>
</body>
</html>

Hope it helps...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.