You are welcome to discuss these questions with your classmates, the
instructor, or a TA, but I encourage you to try to find answers on
your own before you seek help from others. If you make use of any
outside information in answering these questions, or if you receive
help from anyone, you need to acknowledge that along with your answer.
Answers should be prepared with a word processor, printed out, and
submitted at the beginning of class.
function fun1(b, c)
if (b > c)
return fun2(b, c);
return fun2(c, b);
function fun2(x, y)
var z = x - y;
var x = 4;
var y = 1;
var z = 14;
alert( "A. " + fun2(x, y) ); // A. ???
alert( "B. " + fun2(z, x) ); // B. ???
alert( "C. " + z ); // C. ???
alert( "D. " + fun1(x, y) ); // D. ???
alert( "E. " + fun1(y, x) ); // E. ???
z = fun1(x, z);
alert( "F. " + z ); // F. ???
Write down what you expect to be produced by each of the six alerts.
(It's OK to be wrong, just write down what you think the results will
be. You will not be graded on this part.)
Use the button below to get the actual results; write them down.
For each result (A - F), explain why the
results were what they were. In particular, be sure to state what
functions were called, what the actual parameters were when
each function was called, and what the formal parameters
were when each function started to execute.
fun2 was called with actual parameters [what
were the values?]. Inside fun2, formal
parameter x had value ? and formal parameter
y had value ?.