Hello guys,

This is my first post so I hope I have not done anything wrong. I need your help.

I want to do the following. When a user visits my page I want to have a prompt asking the user how many questions they want to take (from 1 till 10). If the user enters e.g 5 then 5 randomly selected questions should be displayed (out of 10 possible). Also, there must be no duplicates. I would like to inform you that I am not experienced in javascript at all. I have done something but I need your help about the arrays. I have put a comment where I need help. I am also open for other ways on how to do that.


html code with 3 questions radio buttons as an example


<title> Submitting information </title> </head>

 <form id="quiz">

 What's the capital of Bulgaria?

 <input type="radio" name="q1" id="city1" value="Sofia"/>
               <label for="city1">Sofia</label> 


 <input type="radio" name="q1" id="city2" value="Buchurest" />
               <label for="city2">Buchurest</label> <br>

 <input type="radio" name="q1" id="city3" value="Skopie" />
               <label for="city3">Skopie</label>

  <br> <br> <br>

     What's the capital of Mexico?

 <input type="radio" name="q2" id="cit1" value="Mexico city"/>
               <label for="cit1">Mexico city</label>


 <input type="radio" name="q2" id="cit2" value="Karakaz" />
               <label for="cit2">Karakaz</label> <br>

 <input type="radio" name="q2" id="cit3" value="Lisbon" />
               <label for="cit3">Lisbon</label>

       <br> <br> <br>
             Who's the current UK prime minister?

  <input type="radio" name="q3" id="qq1" value="David Cameron"/>
               <label for="qq1">David Cameron</label>


  <input type="radio" name="q3" id="qq2" value="Lloyd George" />
               <label for="qq2">Lloyd George</label> <br>

  <input type="radio" name="q3" id="qq3" value="Gordon Brown" />
               <label for="qq3">Gordon Brown</label>



And here is my javascript piece

function randomInt(low, high) 
 // Given   : low <= high 
 // Returns : a random integer in the range [low, high] 
  return Math.floor(Math.random()*(high-low+1)) + low; 

        function randomOneOf(list) 
   // Given  : list is a nonempty list (array) 
   // Returns: a random item from the list 
     return list[randomInt(0, list.length-1)]; 

    var global = prompt("Select No of questions which you want to be               

    // function to document.write specific No of random questions from a set of questions  (between 1 and 10). 
    // For example user may prompt 5 random questions to be displayed out of 10 
    function result()
        // create an array to store the quiz questions
        var arr = new Array();
        arr[0] = ??               //how to store the quiz questions??. Maybe form('quiz').q1 or ??. Thanks
        arr[1] = ??
        arr[2] = ??
         // .. till 10

        // create another array to store the random number questions that should appear
        var newarr = new Array();

        // finding the first random no.
        var s = function randomOneOf(arr)

        // add the first number to the new array of random numbers
        n = 1;

        // add the rest of the questions to the array depending on global var 
        //(how many numbers of questions the user wants)
         while (n <= global)
                // find the 2nd random Number
                n = function randomOneOf(arr)
                for (var i = 0; i < newarr.length; i++)
    // not allowing duplicates within the random numbers
                        if n.value != newarr[i]



            // displaying the random questions 
                for (var k = 0; k < newarr.length; k++)
                        for j = 0; j < arr.length; j++)

                            if (newarr[k] == arr[j])