problems calling my javascript function liabrary.

  roundy 23:50 09 Mar 05
Locked

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:
HTML>

HEAD>

TITLE>
/TITLE>

SCRIPT SRC=stringLibraryTMA.js> /SCRIPT>

SCRIPT>
var result;

result =
(window.prompt('enter','));
result = result + isVowel(aString);
document.write('answer' + result)


/SCRIPT>

/HEAD>

BODY>
/BODY>

/HTML>
can anyone help!

  KwaK 19:20 12 Mar 05

Your HTML isn't quite right...

you have:

HEAD>

TITLE> /TITLE>

SCRIPT SRC=stringLibraryTMA.js> /SCRIPT>

SCRIPT> var result;

It should be:

<HEAD>

<TITLE> </TITLE>

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

<SCRIPT> var result;

etc.

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.

How to get Windows 10 for free | How to install Windows 10: There is still a way to avoid paying…

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

Hands-on with the Star Wars fighting drones you can fly yourself

15 macOS Sierra tips | How to use macOS Sierra: Secret tricks and best new features in Apple's new…