Key for Gold Exam



  1. The point at which indexing begins is known as its:

A.     Origin

B.      Base

C.     Increment

D.     Start

  1. Consider the following code:

var yell=”Woo-Hoo”;

for (i=1; i<5; i=i+2)
{
        yell = yell + “-Hoo”;
   }    
yell = yell + “!”;

document.write(yell);



A.     How many times, if any, will the loop run?  Explain why for full credit.

 

 

 

 

B.      What prints at the end of the code shown?

 

 

 

 

 



3.      ______________________ can include none, one or many ____________________.
 
Choose and circle the best answer pair from below.

 

A.     Arguments :: outputs

B.      Parameters :: values

C.     Functions :: parameters

D.     Variables :: inputs

 

  1. [5] Using the selections given, place the letter under the code next to the term that correctly identifies what it is.  Not all answers will be used.


_____argument

_____parameter

_____value

_____attribute

_____property

_____method

_____object

_____function call

_____function name

_____function declaration

_____function definition

_____send result to point of call

 
 


<html>

<head><title>Conversion Tables</title>

<script type = “text/javascript”>
              A             B

function convertC2F(tempInC)

                   C               D

{

                   //convert to farenheit

                   var tempInF;                                   E

                   tempInF = (9/5)*tempInC +32;      

                   return tempInF;                                            

}

 

document.bgColor = “pink”;

                   F

 

 

 

//this break is only here to make room for the box

 

 

 

 

 

document.write(“<H2>Table of Celsius – Fahrenheit Equivalents </H2>”);

                  G

 

document.write(“<table><th>C </th> <th> H </th>”);

document.write(“<tr><td>-10 </td> <td>” + convertC2F(-10) +  “</td> </tr>”);

                                                                        H

 

document.write(“<tr><td>20 </td> <td>” + convertC2F(20) +  “</td> </tr>”);

                                                                                 I

document.write(“</table>”);

       J

 

</script>

 

[6 points]
Read the following paragraph.  Imagine that you are thinking of writing a program for the situation listed below.  Identify the programming concepts found in the story. DO NOT WRITE CODE!!! Just indicate the part of the story that is an example of the concept.

  1. The Bus Driver

A bus comes to one of the stops on its route.  There are 50 people waiting, of all different ages.  Riding the bus costs $1 if you are 18 or over and .50 cents for passengers under 18 (but any passenger also under the age of 2 rides free).  The bus driver never leaves behind a single passenger and will not pull away as long as people are waiting to board.  Of course, if they don’t have the bus fare, the driver will kick them off and go on to the next person. At the end of the day, the driver writes down on a piece of paper the amount of money collected from fares to turn in to the central base.  The amount of money should be the equivalent of all the fares of the 18 and over passengers plus the fares of the under 18 passengers (those under 2 aren’t counted).

 

·         Identify what in the story could be an example of a variable and explain why:

 

 

 

 

 

·         Identify what in the story could be an example of a conditional and explain why:

 

 

 

 

 

 

·         Identify what in the story could be an example of iteration and explain why:

 

 

 

 

 

 

·         Identify what in the story could be an example of assignment and explain why:

 

 

 

 

 

·         Identify what in the story could be an example of an expression and explain why:

 

 

 

 

 

·         Identify what in the story could be an example of an array and explain why:

 

 

 

 

 

 

  1. What is the difference between a value and a variable?







[3 points]

  1. Name the 3 components of an assignment statement.  Circle the example of each and place an arrow to the term.  Be exact!  Vague circles and arrows will be marked off.

 

price = total * tax

 

 

1)___________________            2)_____________________     3)______________________

 

 

 

  1. Look at the code below (assume it sits in the correct location in an HTML document):

 

<script type=“text/javascript”>

function Suess (fish1, fish2) {

            var fishes;

            fishes = “One fish, two fish ” + fish2 + “ fish, ” + fish1 +  “fish!”

            return fishes;

}

 

</script>

<!--somewhere in the HTML Document -->

……. document.write (Suess(“red”, “blue”));

………

 

What is written to the document at this point?

 

 

 

 

 

  1. Which of the following are legal assignment statements in JavaScript.  Circle all that apply.

A.     2 = num + 1;

B.      zero = “zero”;

C.     “zero” = zero;

D.     zero = 0;

E.      zero + num = 1;

  1. Why are else, return and Boolean not good names for functions or parameters?

 

 

 

 



 

 

  1. Global variables (circle all that apply):

A.     Are declared inside of functions

B.      Can have their values changed from anywhere in the program

C.     Are a way to get input to a function

D.     Can only be changed inside functions

 

  1.   Expressions consist of operators and operands.  Give an example of each of the following types of operators and say what it does:

Relational/Comparison Operator                                                         Logical Operator





  1. Using the while iteration, create a loop that will print from 900 down to 0 by 3s

Example:  900,897,894….etc.

 

 

 

 

 

 

 

 

 

 

  1. In this JavaScript statement:

  1. A function

  2. A condition

  3. An equation

  4. A declaration

  5. An assignment


 
 


if (num1 == num2){

account = “balanced”

}

 

How is this part:

num1 == num2

 

best described?  Pick oneà

 

  1. 400 students have signed up for ARCH200 next quarter.  The professor has a list on the computer which is sorted by student last name.  He wants to write a program find out if the student with the last name “Kutzark” is registered.

a) Using Linear Search, what is the most students the program will have to check?  _______

b) Using Binary Search, what is the most students the program will have to check? ________

Space for calculations (show your work!)[In both cases, the answer can be approximate: off by 1 is OK.]

 

 

 

 

 

 

 

[3 points]

  1. You are helping to write out the code for the George Bush electronic voting program.  Your job is to write the function that tallies votes for each party.  This function will be integrated into a larger program and called when needed. Give your function a name that describes what it does.

 

Assume that there are 2 global variables, DemoTally and RepubTally.  There is a text box named “party” on a form named “vote” where a voter enters in their part affiliation. 

 

They have three choices:  “Democrat”, “Republican” or “Independent”. 

 

Write a function that will add 4 to the RepubTally if the text box shows “Republican”, add 3 to DemoTally if the text box holds “Democrat” and add 2 to RepubTally if the box shows “Independent” .

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  1. Look at the following code for calculating a person’s Body Mass Index in metric units. What index is printed to the page?  SHOW YOUR WORK

 

<HTML><HEAD>

<script type="text/javascript">

<!--

function bmiM ( weightKg, heightM )

            {   

            return weightKg / (heightM * heightM);

            }

//-->

</script>

</HEAD>

<BODY>

<script type="text/javascript">

<!--

      document.write(bmiM(60, 2))

//-->

</script></BODY></HTML>

 

Answer

 
 

 

 

 

 

 


EXTRA CREDIT: (2 points each, total of 4 points)

 

1.      Declare an array called wines with 3 elements.  Initialize the array with these values:

“Riesling”

“Merlot”

“Pinot Noir”

 

 

 

 

 

 

 

 

 

 

 

 

 

2.      In the context of Value Sensitive Design research, what does “informed consent” actually mean?