This Old Man with array
//create global array place holds all the places
place = new Array(
"",
"on my thumb",
"on my shoe",
"on my knee"
);
function main(){
//this old man using arrays
for (verseNum = 1; verseNum < place.length; verseNum++){
alert(verse(verseNum));
alert(chorus());
} // end for loop
} // end main
function chorus(){
// the chorus function is largely unchanged
// except it now returns the chorus as a result
var theSong = "..with a knick-knack \n";
theSong += "paddy-whack\n";
theSong += "give a dog a bone...\n";
theSong += "\n This old man came rolling home \n";
return theSong;
} // end chorus
function verse(verseNum){
// I re-wrote the verse function
// replacing if statements with the array
var theSong = "This old man, \n";
theSong += "He played ";
theSong += verseNum + ". \n";
theSong += "He played knick-knack \n";
theSong += place[verseNum];
return theSong;
} // end verse
Andy Harris