Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to ignore upper and lower case

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to ignore upper and lower case

    Hi .. i have creaated this code but my task is to make this program bellow so that it disregards upper and lower case letters. can anyone please help im stuck with my assignment


    // Create a variable to store the amount of goes left and start it off containing 11
    var goesleft = 11;
    // Define an array with a list of words
    var words = ["practical","programming","software","developm ent"];
    // Generate a random number between 0 and the length of the array and put it into a variable
    var randomnumber=Math.floor(Math.random()*words.length );
    // Get the element of the array at the position of the random number and put it into a variable
    var currentword = words[randomnumber];
    // create a variable to hold the placeholder
    var placeholder = "";
    // repeat for each letter in the current word
    for (var i = 0; i < currentword.length; i++)
    {
    // each repetition, add - to the placeholder variable
    placeholder += "-";
    }

    // Repeat the following steps while the number of goes is > 0
    while (goesleft > 0)
    {
    // Print the placeholder
    println(placeholder);
    // Create a variable to hold the user's guess
    // ...and put user's input into it
    var guess = input("Enter your guess!");
    // this gets set if there's a match
    var match = 0;
    // Repeat for each letter in the "current word" variable
    for (var i=0; i < currentword.length; i++)
    {
    // if this letter in the "current word" is the same as the guess replace the dash in the placeholder
    if (currentword.substr(i,1) == guess)
    {
    placeholder = placeholder.substring(0, i) + guess + placeholder.substring(i+1);
    match = 1;
    }
    }
    // If none of the letters match, decrement the number of goes
    if (match == 0)
    {
    goesleft--;
    }
    // If there are no dashes left in the placeholder, make the number of goes 0 (because they've won)
    if (placeholder.indexOf("-") == -1)
    {
    goesleft = 0;
    }
    }

    println("End of game!");
    println("The word was "+currentword);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,328
    Thanks
    49
    Thanked 2,194 Times in 2,167 Posts

    Default Re: how to ignore upper and lower case

    Please edit your post and wrap the code in code tags: [code] ,,,code here...[/code]

Similar Threads

  1. Which files do I ignore in my version control?
    By ChristopherLowe in forum Android Development
    Replies: 1
    Last Post: January 5th, 2012, 10:39 PM
  2. How do I make this Palindrome tester ignore punctuation?
    By trogan234 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 3rd, 2011, 04:43 AM
  3. wanting to convert printout to UPPER case
    By welikedogs in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 3rd, 2010, 01:22 PM
  4. Listing the alphabet in lower and uppercase
    By Nemphiz in forum Object Oriented Programming
    Replies: 2
    Last Post: May 25th, 2010, 05:25 PM
  5. [SOLVED] upper case
    By andaji in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 13th, 2010, 10:54 PM

Tags for this Thread