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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with array problem

    I have an assinment that I have to do and I need help with the problem. The following is what I need it to do;

    Make a Javascript program that will read an array of 10 to 20 characters and display to the screen a count of the occurrences of each of the five vowels (a, e, i, o, u) in the array.

    I can make the array and every thing but I cannotfind anyway to do the counting portion of it and I need help soon. If someone can give me the code to do it taht would be awesome.

    Thanks, ciwwebdude

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Post the code you have
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code posting

    Here is one of the code that I have started for my problem. Let me know if you can help. Thanks

    <html>
    <body>

    <script type="text/javascript">

    function sortNumber(A,E,I,O,U)
    {
    return A,E,I,O,U
    }
    var characters = new Array(10)
    characters[0] = "A"
    characters[1] = "1"
    characters[2] = "B"
    characters[3] = "J"
    characters[4] = "I"
    characters[5] = "6"
    characters[6] = "E"
    characters[7] = "W"
    characters[8] = "Y"
    characters[9] = "U"

    document.write(characters + "<br />")
    document.write(characters.sort(sortNumber))


    </script>

    </body>
    </html>

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    All you have there is the array, where's the rest of the code you have been working on?
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #5
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I must have deleted the one with the sorting that I did. Ill have to look again and see if I can find it. Any suggestions though on how to do the sorting count for the vowels? Any suggestions or an example of code that I could use would be great.

    Thanks Ciwwebdude

  • #6
    New Coder
    Join Date
    Oct 2005
    Location
    London, United Kingdom
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    var chars = new Array('a', '1', 'b', 'j', 'i', '6', 'e', 'w', 'y', 'u');
    var counts = new Object();
    counts['a'] = counts['i'] = counts['o'] = count['u'] = 0;
    for (var i = 0; i < chars.length; i++) {
      switch (chars[i]) {
        case 'a':
          counts['a']++; break;
        case 'i':
          counts['i']++; break;
        case 'o':
          counts['o']++; break;
        case 'u':
          counts['u']++; break;
      }
    }
    Then the counts['a'] element will contain the numder of 'a' character occurrences in the chars array.
    Code Review 4U - boost your code and skills for
    being social - JavsScript and C# code reviews.

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Well AlexVN, you have just done ciwwebdude homework for him/her so I might as well post mine now.

    The following will also check for mulitple instances of a vowel within the same index

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>
    </
    HEAD>
    <
    BODY>

    <
    div id="display"></div>

    <
    script type="text/javascript">
    <!--
    var 
    characters = new Array()
    characters[0] = "A"
    characters[1] = "1"
    characters[2] = "B"
    characters[3] = "J"
    characters[4] = "I"
    characters[5] = "6"
    characters[6] = "E"
    characters[7] = "W"
    characters[8] = "Y"
    characters[9] = "U"

    vowel=new Array("a","e","i","o","u")

    characterCount=new Array()

    for(var 
    i=0;i<characters.length;i++){
    checkCharacters=characters[i].toLowerCase()

    for(var 
    j=0;j<vowel.length;j++){
    if(
    i==0){characterCount[j]=0}

    nextCharacter=checkCharacters.indexOf(vowel[j])

    while(
    nextCharacter!=-1){
    characterCount[j]++
    nextCharacter=checkCharacters.indexOf(vowel[j],nextCharacter+1)
    }

    }

    }

    for(
    k=0;k<characterCount.length;k++){
    document.getElementById("display").innerHTML+="Number of character "+vowel[k].toUpperCase()+" = "+characterCount[k]+" <br>"
    }

    //-->
    </script>

    </BODY>
    </HTML> 
    Last edited by Mr J; 10-16-2005 at 03:15 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #8
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would ike to thank you, MR J and Alexvn. I have been looking for the code and examples on how to do what i needed. But I could not figure it out. I cant get any help or examples from my instructor and I was at a dead end. i dont think he is any good at java script and he doesnt seem to want to help students. I would like to say that ya'lls javascript skills are awesome. Can you recommend any good books or website to learn java script and areas like the count that you did in the code. I wil probly be talking to you guys through the forum. Again, thanks so much for the help.

    Ciwwebdude


  •  

    Posting Permissions

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