![]() |
|
|
#1
|
|||
|
|||
|
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....
|
|
#2
|
|||
|
|||
|
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;
}
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. |
|
#3
|
|||
|
|||
|
Quote:
Code:
function isVowel(ch)
{
return new RegExp("[aeiou]", "i").test(ch);
}
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
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 |