susie123
09-29-2007, 04:31 PM
Hello
I have written this code and everything works fine except that instead of receiving a total number of WORDS, I´m receiving the total number of characters. Can anybody please advise where I´m going wrong, please?
<script language="JavaScript">
<!--
var wholeName = prompt("Please enter your name & surname.","");
var first_split = wholeName.split(" ");
var resource = first_split[1];
var totalWords = first_split[0];
document.write(totalWords);
alert("Total number of words = " + totalWords.length)
//-->
</script>
Many thanks as always. S
I have written this code and everything works fine except that instead of receiving a total number of WORDS, I´m receiving the total number of characters. Can anybody please advise where I´m going wrong, please?
<script language="JavaScript">
<!--
var wholeName = prompt("Please enter your name & surname.","");
var first_split = wholeName.split(" ");
var resource = first_split[1];
var totalWords = first_split[0];
document.write(totalWords);
alert("Total number of words = " + totalWords.length)
//-->
</script>
Many thanks as always. S