"Multiple Returns"

This Web page calls a function which displays the confirm(). The user clicks the OK or Cancel button. There are two different return statements depending on which button is clicked. The text returned is then displayed in the Web document, below:


<SCRIPT>

function function1() {
     var result = confirm("Click OK or cancel.");

     if (result) return "You pressed the OK button";
     else return "You pressed the Cancel button";
}

</SCRIPT>

<SCRIPT>

var sText = function1();

document.write("<P><H3>" + sText + "</H3><P>");

</SCRIPT>