Just a bit more help!

Discussion in 'JavaScript' started by demondestiny, Aug 25, 2010.

  1. #1
    Hi i've been developing this javascript program that prompts the user for a first number then a second number and then displays all numbers between them two.

    So for eg if a user types in 5 for the first number then 10 for the second it should display it like this,

    5, 6, 7, 8, 9, 10

    It only displays the first number at the moment and not the second, heres the code.

    
    <!-- jsset1_6.html -->
    <html>
      <head>
        <title>jsset1_6.html</title>
          <style type="text/css">
            body {
                  background-color:#000000;
                  color:#FFFFFF;
                  font-size:30;
                  text-align:center;
                 }
          </style>
      </head>
      <body>
        <script type="text/javascript">
          var first, count, stroutput;
          count = 1;
          stroutput = "";
          document.write("<h1>Jsset1_6 - Positive Integers</h1>");
          first = prompt("Enter First Number", "");
          second = prompt("Enter Second Number", "");
          if (first == null)
          {
           stroutput = ("You clicked cancel. No count will be shown.");
          }
          else if (first == "")
          {
           stroutput = ("First Number must be entered.");
          }
          else if (first != parseInt(first))
          {
           stroutput = ("First Number must be a valid whole number");
          }
          else if (second <= first)
          {
           stroutput = ("Second number should not be lower than the first");
          }
          else
          {
          while (count <= first) {
            stroutput = stroutput + count + "\n";
            count = count + 1;
          }
          }
          alert (stroutput);
          document.write("<br /><br />");
          document.write("<br /><br />");
          document.write("<input type='button' name='cmdReload'");
          document.write(" value='Do again' onclick='window.location.reload()' />");
        </script>
    
      </body>
    </html>
    
    Code (markup):
    Many thanks for any help.
     
    demondestiny, Aug 25, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Here is the code that you want:

    
    <!-- jsset1_6.html -->
    <html>
      <head>
        <title>jsset1_6.html</title>
          <style type="text/css">
            body {
                  background-color:#000000;
                  color:#FFFFFF;
                  font-size:30;
                  text-align:center;
                 }
          </style>
      </head>
      <body>
        <script type="text/javascript">
          var first, count, stroutput;
    
          stroutput = "";
          document.write("<h1>Jsset1_6 - Positive Integers</h1>");
          first = parseInt(prompt("Enter First Number", ""));
          second = parseInt(prompt("Enter Second Number", ""));
          if (first == null)
          {
           stroutput = ("You clicked cancel. No count will be shown.");
          }
          else if (first == "")
          {
           stroutput = ("First Number must be entered.");
          }
          else if (first != parseInt(first))
          {
           stroutput = ("First Number must be a valid whole number");
          }
          else if (second <= first)
          {
           stroutput = ("Second number should not be lower than the first");
          }
          else
          {
    
          count = first;
    
          while (count <= second) {
            stroutput = stroutput + count + "\n";
            count = count + 1;
          }
          }
          alert (stroutput);
          document.write("<br /><br />");
          document.write("<br /><br />");
          document.write("<input type='button' name='cmdReload'");
          document.write(" value='Do again' onclick='window.location.reload()' />");
        </script>
    
      </body>
    </html>
    
    Code (JavaScript):
     
    s_ruben, Aug 25, 2010 IP
  3. demondestiny

    demondestiny Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help with this and my other topic as well appreciate it. :)
     
    demondestiny, Aug 25, 2010 IP