Competency Exam 1 Computers and Cognition Name _______________________________
-
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 (a==3)
{
document.write(“is 3” + b + “<br>”);
b=b-2;
c=7;
}
a=a+1;
}
document.write(a+b+c);
-
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.
-
Array Competency: Name ________________________________________