Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2011
    Location
    Europe
    Posts
    26
    Thanks
    20
    Thanked 0 Times in 0 Posts

    JavaScript Username Generator

    Hello.

    I'm new here and learning JavaScript.

    Could you help me to write very simple script to auto generate user name ?

    From any letters. Min 6 - Max 10.


    Like: "jgFJFJ" "KGHGyvk" etc.

    Please help.

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Hi,

    Firstly a random username is bad users wont remeber it

    Secondly the forum rules say no students asking us to work for them and this seems a little like homework so i will give you a run though how to do it then you can google the exact how to's

    username = empty string
    chars = array of charators
    Make a loop for how meany chars in length you want the username
    inside loop set random to a random number using the lenght of chars -1 as the max and 0 as the low then then add the char by using the random number as the key for your chars array

    return the username string
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • Users who have thanked barkermn01 for this post:

    Leos (05-14-2011)

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    1) put all the letters and characters for the username in a string

    2) generate a random number between 6-10

    3) then generate a random number between 0 and the length-1 of the string in 1)

    4) get the character (using charAt()) in the string in 1) at the index of the random number in 3)

    5) repeat steps 3-4 for the number of times of the random number in 2), appending the new character to the previous ones.
    Last edited by bullant; 05-14-2011 at 12:51 PM.

  • Users who have thanked bullant for this post:

    Leos (05-14-2011)

  • #4
    New Coder
    Join Date
    May 2011
    Location
    Europe
    Posts
    26
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Thank you
    I will review it and try to implement
    I will post my results.

    BTW.

    What software is the best to write and test JS ? With debugger etc...
    Last edited by Leos; 05-14-2011 at 01:32 PM.

  • #5
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    no problem

    If you are just starting out then any text editor will be ok and probably try Notepad++. Or if you would like to jump straight into the deep end, then maybe have a look at an IDE like Netbeans which has a lot more bells and whistles..

    For debuging js, I suppose the easiest tool would be Firebug in the Firefox browser or the web developer tools in any of the other major browsers.

    If you're not comfortable using a debugger, you can always use alert()s in your js code to check values of variables etc.

    If you need more help, post back with your code and we can try to help you get it working.

  • Users who have thanked bullant for this post:

    Leos (05-14-2011)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •