I've gotten a little bit ahead.
<html>
<head>
<title>charCodeAt() - Ex. 3</title>
<script language="javascript" type="text/javascript">
var textodoom;
textodoom = "This is Josephine's string";
var charCheck;
var upperInvert = 0;
var lowerInvert = 0;
var letArray = new Array();
var otArray = new Array();
function inverttext() {
for (i=0; i<=(textodoom.length-1); i++) {
charCheck = textodoom.charCodeAt(i);
if ((charCheck > 64) && (charCheck < 91)) {
lowerInvert = (textodoom[i]).toLowerCase();
var lowerRep = (textodoom[i]).replace((textodoom.charAt(i)),lowerInvert);
}
if ((charCheck > 96) && (charCheck < 123)) {
upperInvert = (textodoom[i]).toUpperCase();
var upperRep = (textodoom[i]).replace((textodoom.charAt(i)),upperInvert);
}
document.write(lowerRep + upperRep);
}
}
</script>
</head>
<body>
<form name="buttonForm">
<p id="fancytext">This is Josephine's string</p>
<input type="button" name="imabutton" onClick="inverttext();" value="Click to invert string." />
<p id="othertext"> </p>
</form>
</body>
</html>
When I run the function, it gives me:
tundefinedtHtItStStItStSjSjOjSjEjPjHjIjNjEjEjSjSjS jTjRjIjNjG
How would I be able to stop it from doing that and actually displaying the sentence?
|