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 6 of 6
Like Tree3Likes
  • 1 Post By Philip M
  • 2 Post By Philip M

Thread: Java Code That Gives a Random Word From List Each Time I press The Button ???????????

  1. #1
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Java Code That Gives a Random Word From List Each Time I press The Button ???????????

    Guys please help i need a Java program or a Code that gives me a random word or a sentence each time i press the same button.
    İ am pretty bad at java coding so i kindly request your help please guys.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    This is the JavaScript forum. Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia! Ask a mod to move this thread to the right forum.
    maxim1200 likes this.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you i will be more carefull

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    If you want a Javascript solution, try this:-

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    </head>
    <body>
    
    <script type = "text/javascript">
    
    var myArray = ["A", "B", "C", "D", "E", "F", "G", "H", "J", "K"];  // the words and sentences all in quotes, no comma after the last one
    
    function shuffle(Arr) {
    var NewArr = Arr.slice(0);  // copy the array
    var len = NewArr.length;
    while (len>0) {
    NewArr.push(NewArr.splice(Math.floor(Math.random()*len),1)[0]);
    len--;
    }
    return NewArr;
    }
    
    var copy =shuffle(myArray); // copy array and shuffle
    alert ("Shuffled copy of array:- " + copy);  // for testing
    
    var count = 0;
    function getNext() {
    document.getElementById("mytext").innerHTML = copy[count];
    count ++;
    if (count >= copy.length) {
    count = 0;
    copy =shuffle(myArray); // copy array and shuffle again into a different sequence
    alert ("Shuffled copy of array:- " + copy);  // for testing
    }
    }
    
    </script>
    
    <input type = "button" value = "Get a word or  sentence" onclick = "getNext()">
    <br><br>
    <span id = "mytext"></span>
    </body>
    </html>
    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 05-24-2014 at 07:54 PM.
    maxim1200 and Adam Weishaupt like this.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow maybe i should give it a try in a different way thank you again

  • #6
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,100
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Thread moved to the Java forum.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!


  •  

    Posting Permissions

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