Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. A question to dust_dex

A question to dust_dex

Scheduled Pinned Locked Moved JavaScript
question
16 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D dusty_dex

    Off by one error - range of random 0-12, valid range for Array 0 - 11 Removed an unwanted comma (,) after rec[q] in your document write. :)

    <html>
    <head>
    <script type="text/javascript">
    var rec = ["19","20","21","40","41","45","12","23","34","36","37","46"];
    document.write("Weekly records for 2 week : ");
    for(var i=0; i<12; i++) {
    document.write(rec[i] + ",");
    }
    document.write("
    ");
    for(var z=0; z<6; z++) {
    var q = Math.round(11 * Math.random());
    document.write(rec[q] +", "+ z +" ");
    }
    </script>
    </head>
    <body>
    </body>
    </html>

    "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

    H Offline
    H Offline
    Hakan Bulut
    wrote on last edited by
    #6

    Well.. now how do i prevent adding the numbers of array elements value, array elements only among themselves, I just wanted to combine random.. Output is: 19, 0 23, 1 20, 2 19, 3 34, 4 45, 5 it must be: 19, 23, 20, 19, 34, 45 Why does it wrote the numbers of random array and how do i prevent the same number selection..¿

    Quickly remove the shameless

    H D 2 Replies Last reply
    0
    • H Hakan Bulut

      Well.. now how do i prevent adding the numbers of array elements value, array elements only among themselves, I just wanted to combine random.. Output is: 19, 0 23, 1 20, 2 19, 3 34, 4 45, 5 it must be: 19, 23, 20, 19, 34, 45 Why does it wrote the numbers of random array and how do i prevent the same number selection..¿

      Quickly remove the shameless

      H Offline
      H Offline
      Hakan Bulut
      wrote on last edited by
      #7

      I have to special thanks for all ur helps.

      1 Reply Last reply
      0
      • D dusty_dex

        Off by one error - range of random 0-12, valid range for Array 0 - 11 Removed an unwanted comma (,) after rec[q] in your document write. :)

        <html>
        <head>
        <script type="text/javascript">
        var rec = ["19","20","21","40","41","45","12","23","34","36","37","46"];
        document.write("Weekly records for 2 week : ");
        for(var i=0; i<12; i++) {
        document.write(rec[i] + ",");
        }
        document.write("
        ");
        for(var z=0; z<6; z++) {
        var q = Math.round(11 * Math.random());
        document.write(rec[q] +", "+ z +" ");
        }
        </script>
        </head>
        <body>
        </body>
        </html>

        "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

        H Offline
        H Offline
        Hakan Bulut
        wrote on last edited by
        #8

        I tried the following lines at least.. have you got an idea about this statement?

        document.write("<BR><BR>" + "Combination is :" + "<BR>");
        do(q) { z += 1;
        var q = Math.round(Math.random()* 11);
        if(q==q) {return q;}
        document.write(rec[q] +", "+ z);
        } while(z==6);

        H D 3 Replies Last reply
        0
        • H Hakan Bulut

          I tried the following lines at least.. have you got an idea about this statement?

          document.write("<BR><BR>" + "Combination is :" + "<BR>");
          do(q) { z += 1;
          var q = Math.round(Math.random()* 11);
          if(q==q) {return q;}
          document.write(rec[q] +", "+ z);
          } while(z==6);

          H Offline
          H Offline
          Hakan Bulut
          wrote on last edited by
          #9

          Is there something to way some simple code to do this?

          1 Reply Last reply
          0
          • H Hakan Bulut

            Well.. now how do i prevent adding the numbers of array elements value, array elements only among themselves, I just wanted to combine random.. Output is: 19, 0 23, 1 20, 2 19, 3 34, 4 45, 5 it must be: 19, 23, 20, 19, 34, 45 Why does it wrote the numbers of random array and how do i prevent the same number selection..¿

            Quickly remove the shameless

            D Offline
            D Offline
            dusty_dex
            wrote on last edited by
            #10

            Well you aren't putting the (value of) the z variable into the array. Only showing its value. remove the

            + z +" "

            from document.write

            "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

            1 Reply Last reply
            0
            • H Hakan Bulut

              I tried the following lines at least.. have you got an idea about this statement?

              document.write("<BR><BR>" + "Combination is :" + "<BR>");
              do(q) { z += 1;
              var q = Math.round(Math.random()* 11);
              if(q==q) {return q;}
              document.write(rec[q] +", "+ z);
              } while(z==6);

              D Offline
              D Offline
              dusty_dex
              wrote on last edited by
              #11

              replace with this.

              <script>
              // create and initialise - array to keep track of any number taken
              var taken = new Array(49);
              for (var i=49; i>0; i--) taken[i]=false;

              var lucky = \[\];
              var rec = \["19","20","21","40","41","45","12","23","34","36","37","46"\];
              document.write("Weekly records for 2 week : ");
              for(var i=0; i<12; i++) {
                  document.write(rec\[i\] + ",");
              }
              
              document.write("  
              

              ");

              var z=0;
              do {
                  var q = Math.round(11 \* Math.random());
                  if(!taken\[ rec\[q\] \]) {
                      lucky\[z\] = rec\[q\];
                      taken\[ rec\[q\] \] = true;
                      document.write(lucky\[z\] + "  
              

              ");
              z++;
              }
              } while (z < 6);
              </script>

              this line:

              if(!taken[ rec[q] ])

              checks if NOT taken (! = not)

              "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

              H 1 Reply Last reply
              0
              • H Hakan Bulut

                I tried the following lines at least.. have you got an idea about this statement?

                document.write("<BR><BR>" + "Combination is :" + "<BR>");
                do(q) { z += 1;
                var q = Math.round(Math.random()* 11);
                if(q==q) {return q;}
                document.write(rec[q] +", "+ z);
                } while(z==6);

                D Offline
                D Offline
                dusty_dex
                wrote on last edited by
                #12

                Just letting you know what your errors here are. See my other post for new code.

                do(q)

                can't use expressions at the top of do loop *(q)*, just use

                do {

                z is not declared with var *and* initialised with a value. var z = 0;

                z +=1; // z (undefined) +1 is still undefined

                you don't need the { } braces for a single statement..

                if(q==q) return q;

                but, q==q just evaluates to true so you might as well have just written this

                return q; // if (q==q) {return q;}

                I am not able to reply very quickly. On a training course for another 10 days. Be patient. Please keep trying to write new code as it is easier for me to guess what you are doing. :)

                "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                H 1 Reply Last reply
                0
                • D dusty_dex

                  replace with this.

                  <script>
                  // create and initialise - array to keep track of any number taken
                  var taken = new Array(49);
                  for (var i=49; i>0; i--) taken[i]=false;

                  var lucky = \[\];
                  var rec = \["19","20","21","40","41","45","12","23","34","36","37","46"\];
                  document.write("Weekly records for 2 week : ");
                  for(var i=0; i<12; i++) {
                      document.write(rec\[i\] + ",");
                  }
                  
                  document.write("  
                  

                  ");

                  var z=0;
                  do {
                      var q = Math.round(11 \* Math.random());
                      if(!taken\[ rec\[q\] \]) {
                          lucky\[z\] = rec\[q\];
                          taken\[ rec\[q\] \] = true;
                          document.write(lucky\[z\] + "  
                  

                  ");
                  z++;
                  }
                  } while (z < 6);
                  </script>

                  this line:

                  if(!taken[ rec[q] ])

                  checks if NOT taken (! = not)

                  "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                  H Offline
                  H Offline
                  Hakan Bulut
                  wrote on last edited by
                  #13

                  Excellent code thanks a lot.

                  1 Reply Last reply
                  0
                  • D dusty_dex

                    Just letting you know what your errors here are. See my other post for new code.

                    do(q)

                    can't use expressions at the top of do loop *(q)*, just use

                    do {

                    z is not declared with var *and* initialised with a value. var z = 0;

                    z +=1; // z (undefined) +1 is still undefined

                    you don't need the { } braces for a single statement..

                    if(q==q) return q;

                    but, q==q just evaluates to true so you might as well have just written this

                    return q; // if (q==q) {return q;}

                    I am not able to reply very quickly. On a training course for another 10 days. Be patient. Please keep trying to write new code as it is easier for me to guess what you are doing. :)

                    "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                    H Offline
                    H Offline
                    Hakan Bulut
                    wrote on last edited by
                    #14

                    Finally, ask you for anything more in a array of 12 elemented to 49 membered Argument want to match, you can also help me in this topic? JavaScript writing is so hard really. Thank you for your help. I tried the following lines:

                    var arrNumbers = [49];
                    var arrOutside = [];
                    var arrInside = ["19","20","21","40","41","45","12","23","34","36","37","46"];
                    var z=0;
                    for(var i=0; i<12; i++) { arrInside[i]=false; }

                    for(var j=49; j>0; --j)
                    {
                    arrNumbers[j]=j;

                    if(arrNumbers[j] != arrInside[i]) {
                    document.write(arrNumbers[j]=arrOutside[z], + ", ");
                    arrInside[i] = true;
                    z++;
                    }
                    }

                    if this is what special things I did not want to deal with it.. I do not want to discuss whom it is could not be shy

                    D 1 Reply Last reply
                    0
                    • H Hakan Bulut

                      Finally, ask you for anything more in a array of 12 elemented to 49 membered Argument want to match, you can also help me in this topic? JavaScript writing is so hard really. Thank you for your help. I tried the following lines:

                      var arrNumbers = [49];
                      var arrOutside = [];
                      var arrInside = ["19","20","21","40","41","45","12","23","34","36","37","46"];
                      var z=0;
                      for(var i=0; i<12; i++) { arrInside[i]=false; }

                      for(var j=49; j>0; --j)
                      {
                      arrNumbers[j]=j;

                      if(arrNumbers[j] != arrInside[i]) {
                      document.write(arrNumbers[j]=arrOutside[z], + ", ");
                      arrInside[i] = true;
                      z++;
                      }
                      }

                      if this is what special things I did not want to deal with it.. I do not want to discuss whom it is could not be shy

                      D Offline
                      D Offline
                      dusty_dex
                      wrote on last edited by
                      #15

                      Please explain what inside & outside mean.    inside what?    outside what? arrNumbers = [49]; // array length = 1 ??? I'm guessing this is what you intended arrNumbers = new Array(49); Also, you can't assign (=) inside of document.write()

                      arrOutside[j]=j

                      arrNumbers[j] = arrOutside[z]

                      did you mean to show arrNumbers and arrOutside, or copy from one to another? this does not make sense.

                      arrNumbers[j] && arrInside[i] = true;

                      What other programming language do you know? Because, it might be easier if you write your code in a computer language that you are familiar with. I will be able to figure it out.

                      "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                      H 1 Reply Last reply
                      0
                      • D dusty_dex

                        Please explain what inside & outside mean.    inside what?    outside what? arrNumbers = [49]; // array length = 1 ??? I'm guessing this is what you intended arrNumbers = new Array(49); Also, you can't assign (=) inside of document.write()

                        arrOutside[j]=j

                        arrNumbers[j] = arrOutside[z]

                        did you mean to show arrNumbers and arrOutside, or copy from one to another? this does not make sense.

                        arrNumbers[j] && arrInside[i] = true;

                        What other programming language do you know? Because, it might be easier if you write your code in a computer language that you are familiar with. I will be able to figure it out.

                        "It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan That's what machines are for. Got a problem? Sleep on it.

                        H Offline
                        H Offline
                        Hakan Bulut
                        wrote on last edited by
                        #16

                        It flags to the 49 numbers of numeric lotto arrInside is the numbers two week of and arrOutside is other numbers of 49 that is The number 49 is the number of remaining ..previously worked on the platform of Visual C++ 6.0.. I am thinking you are right JavaScript language is not completely literal a language because of it's called name as script ... arrInside arrOutside are instead of lucky or unlucky they may also like the your previous thread is to be

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups