An N or not a N

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivo

    An N or not a N

    Consider a simple onkeypress script that alerts with messages like
    "You typed a A!"
    I have written a small function that considers when it should be
    "You typed an A!"
    where the variable string is preceded by "an" rather than "a", and would
    appreciate comments, since English is not my mother language and I
    don't know exactly when you say "an" rather than "a". If I feed whole
    words to this function, is a test for the first letter enough?

    function atrailn(n,u){
    var a = ['a','e','f','h' ,'i','l','m','n ','r','s','x',' 8','11','18','8 0' ];
    if( typeof n==='string' ){ n=n.charAt(0); }
    return
    ( u ? 'A' : 'a' ) +
    ( in_array( (''+n).toLowerC ase() , a ) ? 'n' : '' ) +
    ' ' + n;
    }

    function in_array(n,a){
    var i=a.length; while(i--){ if(a[i]===n){ return true; } } return false;
    }

    function alertletter(n){
    alert( 'That was ' + atrailn(n) + '.' );
    }

    --
    Ivo





  • RobG

    #2
    Re: An N or not a N

    Ivo wrote:
    [snip][color=blue]
    > appreciate comments, since English is not my mother language and I
    > don't know exactly when you say "an" rather than "a". If I feed whole
    > words to this function, is a test for the first letter enough?[/color]
    [snip]

    Not really a JavaScript question, perhaps you should try
    microsoft.publi c.word.spelling .grammar. Anyhow, here is a
    site that gives some pointers:



    It is a US institution (Purdue), however it should be OK.
    The main thing is that it is the *sound* that is important,
    not the actual letter.

    e.g. 1. Some people may say "an historical perspective",
    others "a historical perspective". H is not a vowel, but it
    sounds like one in the above context so many people say "an"
    rather than "a".

    e.g. 2. "one" starts with a vowel, but most would say "a one
    hundred percent chance", not "an one hundred..." because
    "one" sounds like it starts with a consonant (i.e."w" as in
    won) so it gets "a" not "an".

    As you have noticed, you will have to convert number to
    words, then test the words. But there are many exceptions
    and many more examples I'm sure.

    Cheers, Fred

    Comment

    • Philip Ronan

      #3
      Re: An N or not a N

      On 29/9/04 8:34 pm, Ivo wrote:
      [color=blue]
      > Consider a simple onkeypress script that alerts with messages like
      > "You typed a A!"
      > I have written a small function that considers when it should be
      > "You typed an A!"
      > where the variable string is preceded by "an" rather than "a", and would
      > appreciate comments, since English is not my mother language and I
      > don't know exactly when you say "an" rather than "a".[/color]

      Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
      other letters of the alphabet. (Yes, that includes "u"!)
      [color=blue]
      > If I feed whole
      > words to this function, is a test for the first letter enough?[/color]

      No. This is actually very difficult to do. Take a look at:
      <http://www.faqts.com/knowledge_base/entry/edit/index.phtml?aid =26340>

      Phil

      --
      Philip Ronan
      phil.ronanzzz@v irgin.net
      (Please remove the "z"s if replying by email)


      Comment

      • Randy Webb

        #4
        Re: An N or not a N

        Philip Ronan wrote:
        [color=blue]
        > On 29/9/04 8:34 pm, Ivo wrote:
        >
        >[color=green]
        >>Consider a simple onkeypress script that alerts with messages like
        >>"You typed a A!"
        >>I have written a small function that considers when it should be
        >>"You typed an A!"
        >>where the variable string is preceded by "an" rather than "a", and would
        >>appreciate comments, since English is not my mother language and I
        >>don't know exactly when you say "an" rather than "a".[/color]
        >
        >
        > Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
        > other letters of the alphabet. (Yes, that includes "u"!)[/color]

        Not sure where you got those rules from, but of the 13 you list, I know
        at least 10 do not fit the rule you provide.

        H is an exception to the consonant rule. If a word begins with a
        consonant, then it uses "a", not "an". X or maybe Q would be an exception.

        The difficulty comes with words that begin with a vowel (including
        sometimes Y), where its not spelling determined, but phonetically
        determined.



        --
        Randy
        comp.lang.javas cript FAQ - http://jibbering.com/faq

        Comment

        • Lee

          #5
          Re: An N or not a N

          Philip Ronan said:[color=blue]
          >
          >On 29/9/04 8:34 pm, Ivo wrote:
          >[color=green]
          >> Consider a simple onkeypress script that alerts with messages like
          >> "You typed a A!"
          >> I have written a small function that considers when it should be
          >> "You typed an A!"
          >> where the variable string is preceded by "an" rather than "a", and would
          >> appreciate comments, since English is not my mother language and I
          >> don't know exactly when you say "an" rather than "a".[/color]
          >
          >Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
          >other letters of the alphabet. (Yes, that includes "u"!)[/color]

          In US English:

          An hour
          A hair

          An onion
          A one-horse town

          An uncle
          A union

          An x-ray
          A xylophone

          An yttrium atom (the only example I can think of for "an y*".
          A yak

          I can't think of any examples of:

          an F*
          an L*
          an M*
          an N*
          an R*
          an S*

          other than when saying the names of the letters, as in:
          "Gimme an 'F'!"

          Comment

          • Philip Ronan

            #6
            Re: An N or not a N

            On 30/9/04 6:07 pm, Randy Webb wrote:
            [color=blue]
            > Philip Ronan wrote:
            >[color=green]
            >> On 29/9/04 8:34 pm, Ivo wrote:
            >>
            >> Use "an" for A, E, F, H, I, L, M, N, O, R, S and X. Use "a" for all the
            >> other letters of the alphabet. (Yes, that includes "u"!)[/color]
            >
            > Not sure where you got those rules from, but of the 13 you list, I know
            > at least 10 do not fit the rule you provide.[/color]

            I was referring to the individual letters, not words that *begin* with those
            letters (which is what the OP was referring to in the text I originally
            quoted).

            I also gave the URL of a web page that explains the problems of applying
            this to whole words (which is what the OP was referring to in the second bit
            of text I originally quoted).

            Here's another URL for you: <http://www.sniffles.ca/wavs/raspberry.wav> :-P

            --
            Philip Ronan
            phil.ronanzzz@v irgin.net
            (Please remove the "z"s if replying by email)


            Comment

            • RobG

              #7
              Re: An N or not a N

              Lee wrote:[color=blue]
              >
              > other than when saying the names of the letters, as in:
              > "Gimme an 'F'!"
              >[/color]

              That's exactly what Phil meant, because that is what the OP
              asked for. He asked how to tell whether to put "a" or "an"
              in front of single letters. Then the OP asked if this same
              rule applies to words.

              Phil's answer is correct on both counts.

              Comment

              Working...