problems calling my javascript function liabrary.

  roundy 23:50 09 Mar 05

I have programed my own 2 functions which I will contain with in a separate js.file. I then wish to import these functions within another javascript file without repeating the code functions again, using SCRIPT SRC=stringLibraryTMA.js> /SCRIPT>.

The 'stringLibraryTMA.js' contains the 2 functions which are as follows:

function isVowel(aCharacter)
/* This function takes one argument, a string which */
/* consists of a single character. The function */
/* returns the Boolean value true if the character is */
/* one of a, A, e, E, i, I, o, 0, 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,aCharacter)
/* Function takes two string arguments, the second argument is a */
/* string containing a single character. The function doubles the */
/* occurrences of aCharacter contained in aString and returns the value. */
var result;
result = ';
for (var position = 0; position aString.length; position = position + 1)
if (aString.charAt(position) == aCharacter)
result = result + result
};return result
I now wish to call for the 'doubleVowels'function using the argument'Hello World' to be displayed as 'Heelloo Woorld'using the following code:



SCRIPT SRC=stringLibraryTMA.js> /SCRIPT>

var result;

result =
result = result + isVowel(aString);
document.write('answer' + result)




can anyone help!

  KwaK 19:20 12 Mar 05

Your HTML isn't quite right...

you have:



SCRIPT SRC=stringLibraryTMA.js> /SCRIPT>

SCRIPT> var result;

It should be:



<SCRIPT SRC=stringLibraryTMA.js> </SCRIPT>

<SCRIPT> var result;


Also the like declaring the js file would probably be better as:

<script src="stringLibraryTMA.js" language="JavaScript" type="text/javascript"></script>

One question, why do you need to import these into another JS file? why not just cut and paste then into your other file keeping all your JS in one file?

Or is this a requirement for your Open University M150 ECA? If that is the case then I think you should be asking your tutor.

Bye for now.

This thread is now locked and can not be replied to.

Hands-on: Acer Predator Triton 700 review

1995-2015: How technology has changed the world in 20 years

This poetic animation about monsters is illustrated in a Van Gogh painterly style

Apple predictions 2017