Switch Statement

[Total: 0    Average: 0/5]

This file shows two things:

Body Code:

<script type=text/javascript>
function showIt() {
  var returnVal = "<FONT COLOR=RED>"
  if (showIt.arguments.length!=0)
    for (var i=0;i<showIt.arguments.length;i++)
      switch(showIt.arguments[i]) {
        case 1: returnVal+="It was one."; break;
      	case 2: returnVal+="It was two."; break;
    	default: returnVal+="I dunno what it was."; break;
      }
  else returnVal += "You must give me a number!"
  returnVal += "</font>"
  return returnVal
}
document.writeln("Pass nota in and get back:  "+showIt()+"<BR>");
document.writeln("Pass in a 1 and get back:  "+showIt(1)+"<BR>");
document.writeln("Pass in a 2 and get back:  "+showIt(2)+"<BR>");
document.writeln("Pass in a 3 and get back:  "+showIt(3)+"<BR>");
document.writeln("Pass in a 1,2,3 and get back: "+showIt(1,2,3)+"<BR>");
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *