Competency Practice Test

Competency Exam 1  Computers and Cognition Sp11   Name _______________________________

 

1. What is the output for the following program: Put a box around your answer:

var a=1, b=7, c=9;
if (a>3)
{
while (c>0)
{
document.write(“nope” + c + “<br>”);
c=c-3
}
}
while ( c > 1)
{
document.write(“inside” + c + “<br>”);
if (a<5)
{
if (b>2)
{
while (b!=4)
{
document.write(“go for” + b + “<br>”);
b=b-1
}
document.write(“more” + a + “<br>”);
}
document.write(“yes” + b + “<br>”);
}
document.write(“again” + c + “<br>”);
c=c-2;
}

SEE IT RUN and SEE SOLUTION

2.  Write a JavaScript program to solve the following problem.  Show your English also.

Enter test scores until the user enters a number less than 0.  For each test score, tell the user if it is an even number over 90.  After you exit the loop,  Print how many even numbers were over 90, the average of all the odd scores in the 80s, and the highest even score less than 70.

 

 

3. Give the output for the following code. Show the runtime stack.

 

function junk(a,b)

{

var c=a-1;

document.write(“first” + a + b + c + “<br>”);

a=b+1;

c=c-1;

document.write(“last” + a + b + c + “<br>”);

return a;

}

 

function stuff(b,c)

{

b=b-1;

a=7;

document.write(“one” + a + b + c + “<br>”);

c=junk(b,a);

document.write(“done” + a + b + c + “<br>”);

}

 

a=3;  b=2;  c=9;

document.write(“start” + a + b + c + “<br>”);

b = junk(c,a);

document.write(“main” + a + b + c + “<br>”);

stuff(a,c);

document.write(“end” + a + b + c + “<br>”);

 

 SEE IT RUN

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>