Function Read Competency

Function Read Code Competency:

Give the output for the following program.  Show the runtime stack:

<html>
<body>

<script type=”text/javascript”>

function first(a,b)
{
document.write(“start” + a + b + c + “<br>”);
a=a+2;
c=c-1;
document.write(“end” + a + b + c + “<br>”);
return c-a;
}

function second(b)
{
a=4;
document.write(“begin sec” + a + b + c + “<br>”);
c=first(b,a);
document.write(“start” + a + b + c + “<br>”);
}

a=1;  b=5;  c=9;
document.write(“init” + a + b + c + “<br>”);
a = first(b,a);
document.write(“main” + a + b + c + “<br>”);
second(a);
document.write(“over” + a + b + c + “<br>”);
</script>
</body>

</html>

http://ada.evergreen.edu/~vanetta/readfunctions/functionRead1.html

Another Example:

<html>
<body>

<script type=”text/javascript”>

function first(a,b)
{
document.write(“start” + a + b + c + “<br>”);
a=a+2;
c=c-1;
document.write(“end” + a + b + c + “<br>”);
return c-a;
}

function second(b)
{
a=4;
document.write(“begin sec” + a + b + c + “<br>”);
c=first(b,a);
document.write(“start” + a + b + c + “<br>”);
}

a=1;  b=5;  c=9;
document.write(“init” + a + b + c + “<br>”);
a = first(b,a);
document.write(“main” + a + b + c + “<br>”);
second(a);
document.write(“over” + a + b + c + “<br>”);
</script>
</body>

</html>

http://ada.evergreen.edu/~vanetta/readfunctions/functionRead2.html