Competency Test Week 7

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=2, b=7, c=9;
while ( a < 5 )
{
document.write(“Junk” + a + “<br>”);
while(c>5)
{
document.write(“in loop”+c+ “<br>”);
c=c-1;
if (c==6)
{
document.write(“More”+c+ “<br>”);
c=c-1;
}
}
if (a==3)
{
document.write(“is 3″ + b + “<br>”);
b=b-2;
c=8;
}
a=a+1;
}
document.write(a+b+c);

 

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

function first(a,b)
{

var c = 7;
document.write(“start” + a + b + c + “<br>”);
b = 8;
document.write(“end” + a + b + c + “<br>”);
return c-a;
}

function second(b)
{
a=4;
document.write(“Junk” + a + b + c + “<br>”);
c=first(b,a);
document.write(“Stuff” + 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>”);

 
Write Code: No Arrays: Name ________________________________

Write a JavaScript program that gets scores from the user until a negative number is entered. If a score is over 90, output “good job” and ask for that person’s name. When you exit the loop, print the average of all scores less than 90 and the highest even score in the 70s.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4. Array Competency: Name ________________________________________
Given you have a filled array of test scores. Write a function that is passed in this array and prints the highest score that is less than the average of all scores. Also print the average of all even scores more than 20 points below the highest score in the list.