title: Create a Javascript function, which generates a random character id comprising of alphabets and numbers for given input length
body: <p>I have completed a JavaScript course and now I am stuck with first Hands-on problem. The question is <strong>"How to generate Random Character id"</strong></p>
  
  <p>Review below screen:</p>
  
  <p>HTML code</p>
  
  <p><a href="https://i.stack.imgur.com/OlqBF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OlqBF.jpg" alt="enter image description here"></a></p>
  
  <p>JavaScript Code.</p>
  
  <p><a href="https://i.stack.imgur.com/DqQxl.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DqQxl.jpg" alt="enter image description here"></a></p>
  
  <p>Error message</p>
  
  <p><a href="https://i.stack.imgur.com/SskwW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SskwW.jpg" alt="enter image description here"></a></p>
  
  <p>Please let me know your suggestions</p>
  
  <p>Thanks</p>
  
  <p>The code I used after few suggestions is as below:</p>
  
  <pre><code>function stringGen(yourNumber){
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  
    for (var i = 0; i &lt; yourNumber; i++)
      text += possible.charAt(Math.floor(Math.random() * possible.length));
  
   return text;
  }
  
  stringGen(10);
  </code></pre>
  
  <p>I get the below error when I test the code in Node.js in Hackerrank</p>
  
  <pre><code>09 10 2018 06:15:13.648:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/                                                      
  09 10 2018 06:15:13.651:INFO [launcher]: Launching browser jsdom with unlimited concurrency                                                    
  09 10 2018 06:15:13.656:INFO [launcher]: Starting browser jsdom                                                                                
  09 10 2018 06:15:13.828:INFO [Node.js (linux; U; rv:v8.9.4)]: Connected on socket 1L0-mKrQnWEv092UAAAA with id 34735969                        
  Node.js (linux; U; rv:v8.9.4) Random string checking random number FAILED                                                                      
          Expected 0 to be 4.                                                                                                                    
              at UserContext.&lt;anonymous&gt; (test/index_test.js:17:33)                                                                              
  Node.js (linux; U; rv:v8.9.4) Random string comparing random numbers FAILED                                                                    
          Expected true to be false.                                                                                                             
              at UserContext.&lt;anonymous&gt; (test/index_test.js:26:16)                                                                              
  Node.js (linux; U; rv:v8.9.4): Executed 2 of 2 (2 FAILED) ERROR (0.031 secs / 0.016 secs)                                                      
  npm ERR! Test failed.  See above for more details.  
  </code></pre>