problems calling my javascript function liabrary.

  roundy 23:50 09 Mar 2005

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 2005

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.

Elsewhere on IDG sites

OnePlus 5T review: Hands-on

Illustrator Andrés Lozano on his improv line work, brazen use of colours & hand sketching

iPhone X review

Comment envoyer gratuitement des gros fichiers ?