Digital Point Forums
Quick Collect

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Mar 14th 2005, 4:56 am
zool_375 zool_375 is offline
Peon
 
Join Date: Mar 2005
Posts: 1
zool_375 is on a distinguished road
Question function help for a complete newbie

Hi,

I need help with the following, i'm a complete newb so bare with me I have written two functions stored in an external library file "library.js" as follows :-

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

function doubleVowels(aString)
/*******************************************************/
/* This function takes a string as its argument and */
/* returns, as its result, a new string similar to the */
/* argument except that the vowels have been doubled */
/*******************************************************/
{
resultString = '';

for (var count = 0; count < aString.length; count = count + 1)
{
if (isVowel(aString.charAt(count)))
{
resultString = resultString + aString.charAt(count) + aString.charAt(count);
}
resultString = aString.charAt(count);
};

result = resultString
return result;
}

Basically the first function should look at each char and return true or false i say 'should' as i'm not sure if it works yet , the second function takes a string and looks at each char (using the first function) to see if it's a vowel, if it is a vowel then it adds it to the string e.g " hello " becomes " heelloo ". the html to make the whole thing work, or not work is as follows :-
HTML>
<HEAD>
<TITLE>vowels
</TITLE>
<SCRIPT SRC = "Library.js"> </SCRIPT>
<SCRIPT >


var answer;




doubleVowels('hello'); /*sends string 'hello' to function doublevowels

answer = doubleVowels(result); /* assigns result of function to variable

window.alert(+ answer); /* displays result in alert box


</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML

At the moment NAN is returned in the alert box. This is a really simple problem, but I am tearing my hair out trying to get it to work, I know i'm 99% there, please help before I have no Hair left....
Reply With Quote
  #2  
Old Mar 15th 2005, 8:34 am
nullbit nullbit is offline
Hand of A'dal
 
Join Date: Feb 2005
Posts: 489
nullbit is on a distinguished road
I made a few revisions, it should work.


Head:
Code:
function isVowel(aCharacter)
{
  return ((aCharacter == 'a') ||
          (aCharacter == 'A') ||
          (aCharacter == 'e') ||
          (aCharacter == 'E') ||
          (aCharacter == 'i') ||
          (aCharacter == 'I') ||
          (aCharacter == 'o') ||
          (aCharacter == 'O') ||
          (aCharacter == 'u') || 
          (aCharacter == 'U'))
}

function doubleVowels(aString)
{
  var resultString = '';

  for(var count = 0; count < aString.length; count ++)
  {
    if(isVowel(aString.charAt(count)))
      resultString += aString.charAt(count) + aString.charAt(count);
    else
      resultString += aString.charAt(count);
  }

  return resultString;
}
Body:
Code:
var word = 'hello';

var answer = doubleVowels(word); /* assigns result of function to variable */

window.alert(answer); /* displays result in alert box */
__________________
SEO Tool - The killer search engine optimization tool. No. Really.
The Search Engine Experiment - Discover if Google really giving you the most relevant results
- No recip required.
Reply With Quote
  #3  
Old Mar 15th 2005, 8:44 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by zool_375
return ((aCharacter == 'a') || (aCharacter == 'A') ||
(aCharacter == 'e') || (aCharacter == 'E') ||
(aCharacter == 'i') || (aCharacter == 'I') ||
(aCharacter == 'o') || (aCharacter == 'O') ||
(aCharacter == 'u') || (aCharacter == 'U'))
Here's a simpler version:

Code:
function isVowel(ch)
{
    return new RegExp("[aeiou]", "i").test(ch);
}
J.D.
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie with stupid question need help jalika Search Engine Optimization 5 Jan 10th 2009 9:23 pm
Complete Redesign nfzgrld Websites 12 Feb 24th 2005 12:09 pm
Newbie - How do I optimize my site?????? www.e-booked.com Search Engine Optimization 7 Feb 14th 2005 4:07 pm
My newbie questions iamrussell Co-op Advertising Network 3 Dec 17th 2004 11:52 pm
New, Newbie...I gladly accept the Mantle comval Introductions 14 Aug 24th 2004 4:05 am


All times are GMT -8. The time now is 5:12 pm.