Competency Exam 1 Computers and Cognition Sp14 Name ____________________________
- What is the output for the following program: Put a box around your answer:
var a=1, b=7, c=0;
while ( a < 5 )
{
if (a>2)
{
document.writeln(“One” + a + c + “<br>”);
if (b>a)
{
while ( b > 2)
{
c=c+1;
document.writeln(“Two” + b + c+ “<br>”);
if ( b == 3)
{
document.writeln(“Three” + b + c+ “<br>”);
b=b-1;
}
b=b-2;
c=c+1;
}
}
if (a==3)
{
document.write(“Stop” + a + b + c + “<br>”);
b = 6;
}
}
document.writeln(“Four” + a + c + “<br>”);
a = a + 1
}
Write a JavaScript program to solve the following problem. Show your English also.
Enter test scores until the user enters an odd number less than 10. For each number entered, print “is a C” if this score is between 70 and 80. After you exit the loop, print the average of all the odd numbers less than 70 and the highest even number.
Competency Test, Functions and Arrays. May 10, Spring 14 Name ______________________________________
Give the output for the following code. Show the runtime stack.
function one(a,b)
{
var c=a-1;
document.write(“yes” + a + b + c + “<br>”);
a=b+1;
c=c-1;
document.write(“no” + a + b + c + “<br>”);
return a;
}
function two(b,c)
{
b=b-1;
a=7;
document.write(“first” + a + b + c + “<br>”);
c=one(b,a);
document.write(“last” + a + b + c + “<br>”);
}
a=3; b=5; c=9;
document.write(“one” + a + b + c + “<br>”);
b = one(c,a);
document.write(“two” + a + b + c + “<br>”);
two(a,c);
document.write(“three” + a + b + c + “<br>”);
4. Array Competency: Given you have a filled array of test scores. Write a function that is passed in this array and prints the highest even score in the array. The function then prints the average of all the odd scores that are less than the highest even score in the array. Finally, your function prints all the even scores that are over