I have completed a JavaScript course and now I am stuck with first Hands-on problem. The question is "How to generate Random Character id"
Review below screen:
HTML code
JavaScript Code.
Error message
Please let me know your suggestions
Thanks
The code I used after few suggestions is as below:
function stringGen(yourNumber){
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < yourNumber; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
stringGen(10);
I get the below error when I test the code in Node.js in Hackerrank
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.<anonymous> (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.<anonymous> (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.