<html>
<head>
<script type = “text/javascript”>
<!–
var a=1, b=7, c=9;
while ( a < 5 )
{
if (a>2)
{
document.write(“Junk” + a + b + c + “<br>”);
while(c>5)
{
document.write(“in loop”+ a + b +c+ “<br>”);
c=c-1;
}
if (a==3)
{
document.write(“is 3″ + a + b + c + “<br>”);
b=b-2;
c=7;
}
}
document.write(“Move” + a + b +c + “<br>”);
a=a+1;
}
document.write(“end” + a+b+c);

 

 

 

 

 

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

<html>
<head>
<script type = “text/javascript”>
function first(a,c)
{

var b = 2;
document.write(“more” + a + b + c + “<br>”);
a = 8;
document.write(“less” + a + b + c + “<br>”);
return c+1;
}

function second(b)
{
a=6;
document.write(“Stop” + a + b + c + “<br>”);
c=first(a,b);
document.write(“Go” + a + b + c + “<br>”);
}

a=1; b=7; 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 score over 100bis entered. For each score, tell if it is odd or even. When you exit the loop, print the highest score under 70. Also print the average of all odd scores over 70. Finally, tell if there where more scores at or over 70 than there were under 70.

 

 

Competency Exam 1 Computers and Cognition Sp14 Name _____________________________

<html>
<head>
<script type = “text/javascript”>
<!–
var a=2, b=7, c=9;

document.write(“Do again” + a + “<br>”);
if (b>5)
{
document.write(“Over” + a + “<br>”);
}
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(“Repeat” + a+b+c);
</script>
</head>
</html>

 

 

 

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

function one(a,b)
{

var c=a-1;
document.write(“first” + a + b + c + “<br>”);
a=b+1;
document.write(“second” + a + b + c + “<br>”);
return a;
}

function two(b,c)
{
a=7;
document.write(“begin” + a + b + c + “<br>”);
c=one(b,a);
document.write(“end” + a + b + c + “<br>”);
}

a=3; b=4; c=9;
document.write(“start” + a + b + c + “<br>”);
b = one(c,a);
document.write(“middle” + a + b + c + “<br>”);
two(a,c);
document.write(“last” + a + b + c + “<br>”);

 

Write Code: No Arrays: Name ________________________________

Write a JavaScript program that gets scores from the user until a score less than 10 is entered. For each score, tell if it is under or over 70. When you exit the loop, print the average of all the even scores. Print the highest odd score in the 80s. Tell if there were more students above or below 70 in the stack of test scores.

 

 

 

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

 

 

4. Array Competency: Name ________________________________________
Given you have a filled array of test scores. Write a function that is passed in this array and then finds the average of all scores between 70 and the highest score in the list. Also print out if there were more or less scores over the average of all the test scores.. For example, if the average of all scores was 75, and there were 21 scores below that and 18 above 75 then print “there were more scores below the average.