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 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a function

    I have created 2 functions, one to test if a charater is a vowel and the other remove a vowel.
    I can't seem to get the dropVowel function to erhm 'Function propally'!!!
    Please advise on what i am doing wrong?



    function isVowel(aCharacter)
    /************************************************************************/
    /*Function takes one argument, a string which consists of a single */
    /*character. The function returns the boleen value true if the character*/
    /*is one of a, A, e, E, i, I, o, O, u, U. If the character is not one of*/
    /*these the function returns the bolean value false. */
    /************************************************************************/
    {
    return ((aCharacter == 'a') ||
    (aCharacter == 'A') ||
    (aCharacter == 'e') ||
    (aCharacter == 'E') ||
    (aCharacter == 'i') ||
    (aCharacter == 'I') ||
    (aCharacter == 'o') ||
    (aCharacter == 'O') ||
    (aCharacter == 'u') ||
    (aCharacter == 'U'))
    };

    function dropVowels(aString)
    /************************************************************************/
    /*Function takes one argument, a string. */
    /*Function returns a new string with vowels removed. */
    /************************************************************************/
    {

    var resultString;

    resultString = '';

    for (var position = 0; position < aString.length; position = position + 1)
    {
    if (aString.charAt(position) ! isVowel(aCharacter))
    {
    resultString = aString.charAt(position)
    }
    };
    return resultString
    };

    Thanks for your time and effort
    STaLLiON

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Suggested reading:
    http://devedge.netscape.com/library/...p.html#1010922

    - it will enable you to have a single line instead of a page you posted
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't really think this helped on the question asked,
    replies on the given subject would be more usefull or am i just being thick and you have really helped me!!!

    What i really need is to be able to create the function and understand how i did it so i thought i could get an answer and then reverse engineer the outcome and maybe, just maybe it might sink in

    Please help
    Regards
    STaLLiON

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    function dropVowels(s) {
    	return s.replace(/[aeiou]/gi, '');
    }
    Hope that helps!

    Happy coding!

  • #5
    New Coder
    Join Date
    Jul 2002
    Location
    Los Angeles
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Vladdy pointed you to a Regular Expressions (RegExp) lesson. nolachrymose's solution was the use of RegExp.

    your two functions can look like this:
    Code:
    function isVowel(aCharacter) {
    	if(aCharacter.match(/[aeiou]/gi))
    		return true;
    	else 
    		return false;
    }
    
    function dropVowels(s) {
    	return s.replace(/[aeiou]/gi, '');
    }

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    isVowel can be even shorter:
    Code:
    function isVowel(aCharacter) 
      { return aCharacter.match(/[aeiou]/gi);
      }
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    And it could be better coded as:
    Code:
    String.prototype.isVowel=function(){
        return /[aeiou]/gi.test(this);
    // Y can also be a wovel (e.g. as used in pry, but not as used in yeast),
    // as can W - but they can act as consonants as well.
    // Any suggestions as to handling this?
    };
    Last edited by liorean; 06-10-2004 at 12:47 AM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't think there would be any simple way to do this, because "y" is be a vowel in "pry," but it's not in "lonely" and other adverbs (and other words, but adverbs just tend to end in "ly.")

    Happy coding!

  • #9
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Cheers Guys

    This has really helped

    Regards
    STaLLiON

  • #10
    New to the CF scene
    Join Date
    Jul 2004
    Location
    London
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hey Stallion

    So why you called Stallion....?

    Looked at your code - was wondering how you got on with it...?

    Can you post the working version - I'm curious, just picking up this stuff myself - having similar problems....

    Catch you soon.

    Penelope.
    x

  • #11
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by penelope_p
    So why you called Stallion....?
    maybe he's been drinking Shrek's magic love potion

    Quote Originally Posted by liorean
    Code:
    String.prototype.isVowel=function(){
        return /[aeiou]/gi.test(this);
    // Y can also be a wovel (e.g. as used in pry, but not as used in yeast),
    // as can W - but they can act as consonants as well.
    // Any suggestions as to handling this?
    };
    perhaps you could invoke an RPC on a dictionary using XmlHttpRequest, checking to see that certain dubious chars in the string are vowels or consonants?


  •  

    Posting Permissions

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