Javascript Help

Discussion in 'JavaScript' started by satrebor, Feb 11, 2013.

  1. #1
    I need a program which will generate typed number of random numbers from 1 to 100. Numbers should be declared in arrays. All numbs have to be sorted descending order. And it should print generated numbers and also print sorted numbers.

    For example. I typed 4. Program genereated 4 random numbers: 22,80,39,79.

    Program will print:

    22,80,39,79
    80,79,39,22

    Pls help, this is my homework that I can not do it.
     
    satrebor, Feb 11, 2013 IP
  2. wonay

    wonay Well-Known Member

    Messages:
    468
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    140
    #2
    Here is a pages online that can do it for you for free....

    graphpad.com/quickcalcs/randomN1.cfm

    Hope this helps!
     
    Last edited: Feb 11, 2013
    wonay, Feb 11, 2013 IP
  3. satrebor

    satrebor Active Member

    Messages:
    244
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    65
    #3
    No, I need a code, to show for my teacher..
     
    satrebor, Feb 11, 2013 IP
  4. wonay

    wonay Well-Known Member

    Messages:
    468
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Sorry but I cannot write the javascript code so quickly.
    Hopefully someone else will help you out with the JS code.
     
    wonay, Feb 11, 2013 IP
  5. satrebor

    satrebor Active Member

    Messages:
    244
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    65
    #5
    Would be great, I dont need it quickly. +rep for this if I can?
     
    satrebor, Feb 11, 2013 IP
  6. wonay

    wonay Well-Known Member

    Messages:
    468
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Then there is another piece of code that can give something like what you want...
    Take a look at it here...

    stackoverflow.com/questions/3796786/random-number-generator-without-dupes-in-javascript
     
    Last edited: Feb 11, 2013
    wonay, Feb 11, 2013 IP
  7. satrebor

    satrebor Active Member

    Messages:
    244
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    65
    #7
    LOL, do not write here, if you dont know.. The most complicated code is the sorting part.
     
    satrebor, Feb 11, 2013 IP
  8. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #8
    Rukbat, Feb 12, 2013 IP
  9. jhine

    jhine Active Member

    Messages:
    25
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    53
    #9
    var nums = [];
    var typed = 5;
    for (var i = 0; i < typed; i++) {
        nums[i] = Math.ceil(Math.random() * 10);
    }
    nums.sort(function(a,b){return a - b});
    nums.reverse();
    Code (markup):
    Something like that?
     
    jhine, Feb 15, 2013 IP