Hi out there
I’m trying to write some code to take a string and convert it into a “coded” string. Seemed to be going OK cept i’m supposed to b doing it using 2 functions – I’m OK if just use the function called makeCode but as soon as I use doMakeCode as well, instead of getting a string returned I get “undefined”. Heres my attempted code including doMakeCode, if anyone can point me in right direction i’d b real greatful – i think i’m going mad with frustration!!!!
<HTML>
<HEAD>
<TITLE>code</TITLE>
<SCRIPT>
function makeCode(aString)
{
var codeArray = [‘q’,’w’,’e’,’r’,’t’,’y’,’u’,’i’,’o’,’p’,’a’,’s’,’d’,’f’,’g’,’h’,’j’,’k’,’l’,’z’,’x’,’c’,’v’,’b’,’n’,’m’];
var codeString;
var output = new Array();
for (var position = 0; position < aString.length; position++)
output[output.length] = codeArray[aString.charCodeAt(position)-97]
return output.join(”);
};
function doMakeCode()
{
var firstString,encodedString;
document.crypt.outString.value = ”;
firstString = document.crypt.inString.value;
firstString = firstString.toLowerCase();
encodedString = makeCode(givenString);
document.crypt.outString.value = encodedString;
document.crypt.inString.focus();
};
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME = “crypt”>
Type message
<BR>
<INPUT TYPE = “text”
NAME = “inString”
VALUE = ”>
<BR>
<INPUT TYPE = “button”
VALUE = “Code”
ONCLICK = “document.crypt.outString.value = makeCode(document.crypt.inString.value)”>
<BR>
Coded message
<BR>
<INPUT TYPE = “text”
NAME = “outString”
VALUE = ”>
<BR>
</FORM>
</BODY>
</HTML>