This old man
demonstrates function parameters
Source code
function main(){
// note that now we are outputting the results of
// the function calls
alert(verse(1));
alert(chorus());
alert(verse(2));
alert(chorus());
} // 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
// so there's only one... It take a
// verse number as a parameter and
// automatically displays the correct information
if (verseNum == 1){
place = "on my thumb... \n";
} // end if
if (verseNum == 2){
place = "on my shoe... \n";
} // end if
var theSong = "This old man, \n";
theSong += "He played ";
theSong += verseNum + ". \n";
theSong += "He played knick-knack \n";
theSong += place;
return theSong;
} // end verse
Andy Harris