SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Location
    Bridgeport, Connecticut, United States
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Making Loop to Search an array

    here is my assignment.

    Code JavaScript:
    Below you will find an array of names to use in this problem.
     
    input[0] should contain a number, which we will call n.
    input[1] should contain a number, which we will call i.
    input[2] should contain a letter, which we will call l.
    You are to create a program which looks at all the names from 0 through n;
    if the letter l, upper or lower case, appears in the name at position i, 
    then the name should be printed along with a message like:
    xxxxxx contains the letter l at position i
    where xxxxxx is the name, l is the letter from input[2] and i is the
    position from input[1].
    If the input n is greater than the number of names, 
    an error message should be printed and no names should be examined.
    If a particular name does not have i characters, 
    it should not cause an error message, but that name should be ignored. That is, if i is 6, Iowa should be ignored.

    I figure i have to create a loop to search through the array of:

    Code JavaScript:
    var names = new Array();
    names[0] = "Alabama";
    names[1] = "ALASKA";
    names[2] = "Arizona";
    names[3] = "Arkansas";
    names[4] = "California";
    names[5] = "Colorado";
    names[6] = "Connecticut";
    names[7] = "Delaware";
    names[8] = "Florida";
    names[9] = "Georgia";
    names[10] = "Hawaii";

    But i am not sure how to do this. Im researching loops now. Any links would be helpful. Im obviously a nub.
    Hate is not appreciated, just some love for the newbie. ;-)

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    This might help - for loops
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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