Please enable JavaScript to use CodeHS

Sample A No Scoring

By David Burnham

Part 3: Written Response

3A.

Provide a written response that does all three of the following: 

i. Describes the overall purpose of the program

ii. Describes what functionality of the program is demonstrated in the video

iii. Describes the input and output of the program demonstrated in the video




The purpose of this program is to test basic math problems in multiplication and division and report the percent correct back to the user. The video demonstrates both the multiplication and division quizzes where the user is asked for the problem type and then given 5 problems, each with a chance to answer and the results reported back.


The video demonstrates 2 different inputs and 3 different outputs. The inputs demonstrated are asking users to select a problem type and then providing a guess for the problems. The three outputs demonstrated are outputting the problem, outputting the results from each guess, and outputting the final score at the end.


3B.

Capture and paste two program code segments you developed during the administration of this task that contain a list (or other collection type) being used to manage complexity in your program.

i. The first program code segment must show how data have been stored in the list. 

ii. The second program code segment must show the data in the same list being used, such as creating new data from the existing data or accessing multiple elements in the list, as part of fulfilling the program’s purpose. 

Then, provide a written response that does all three of the following:

iii. Identifies the name of the list being used in this response

iv. Describes what the data contained in the list represent in your program

v. Explains how the selected list manages complexity in your program code by explaining why your program code could not be written, or how it would be written differently, if you did not use the list 





First code segment:

var firstNumber = [8, 12, 6, 20, 10];
var secondNumber = [2, 3, 3, 4, 5];

Second code segment:

if (type == "M"){
   println(firstNumber[i] + " * " + secondNumber[i]);
   correct = firstNumber[i] * secondNumber[i];
}
else{
   println(firstNumber[i] + " / " + secondNumber[i]);
   correct = firstNumber[i] / secondNumber[i];
}


The program uses two lists, firstNumber and secondNumber. Each list stores the values that are used in the math problems. firstNumber stores the first number in the problem and secondNumber stores the second number, which is the divisor for division problems.


The lists manages complexity in two different ways. First, by using the lists instead of individual variables, the list can store all the values in one variable and use a loop to create the problem. This also allows the program to expand easily by setting the loop length to the length of the lists. Without list, the program would have to use individual variables and written sequentially instead of with a loop.


Additionally, by storing the specific values for the problem it allows for the program to create division problems that result in integer answers. If the program generated random numbers, it would be much more complex to create problems that would result in integer answers.


3C.

Capture and paste two program code segments you developed during the administration of this task that contain a student-developed procedure that implements an algorithm used in your program and a call to that procedure.

i. The first program code segment must be a student-developed procedure that:

• Defines the procedure’s name and return type (if necessary)

• Contains and uses one or more parameters that have an effect on the functionality of the procedure

• Implements an algorithm that includes sequencing, selection, and iteration

ii. The second program code segment must show where your student-developed procedure is being called in your program.

Then, provide a written response that does both of the following:

iii. Describes in general what the identified procedure does and how it contributes to the overall functionality of the program

iv. Explains in detailed steps how the algorithm implemented in the identified procedure works. Your explanation must be detailed enough for someone else to recreate it.



First code segment:

function calculate(type){
    var score = 0;
    var correct;
    for (var i=0; i < numProblems; i++){
        if (type == "M"){
            println(firstNumber[i] + " * " + secondNumber[i]);
            correct = firstNumber[i] * secondNumber[i];
        }
        else{
            println(firstNumber[i] + " / " + secondNumber[i]);
            correct = firstNumber[i] / secondNumber[i];
        }
        println();
        var answer = readInt("Enter your answer: ");
        if (answer == correct){
            println("Correct!");
            score ++;
        }
        else{
            println("Good try!");
        }
        println();
    }
    return score;
}


Second code segment:

var score = calculate(type) * 100 / numProblems;


The selected function contributes to the overall execution of the program by executing the quiz questions and returning how many questions were correct. The function takes the type of questions as an input and then returning the number of correct answers back to the main program.


The function does this by looping through all the values in the list to create a problem. Inside the loop, the function starts by printing out the first number of the problem from the firstNumber list. It then uses a selection statement to print out the operator and calculate the correct answer for either a division or multiplication problem based on the passes parameter. Next, it prints out the second number from the secondNumber list and asks the user for their guess. Using a selection statement, it compares the correct answer to the user's input and reports out the results. If the answer is correct, it also adds to a tracker variable that keeps track of the number of correct answers. At the end of the loop, the function terminates by returning the number of correct answers.


3D.

Provide a written response that does all three of the following:

i. Describes two calls to the procedure identified in written response 3c. Each call must pass a different argument(s) that causes a different segment of code in the algorithm to execute.

ii. Describes what condition(s) is being tested by each call to the procedure

iii. Identifies the result of each call



The two test cases are based on passing a different input to create different types of problem in the function (multiplication versus division). The first call will pass the letter M. Based on this call, the program should select a multiplication problems to print out. Inside the loop, the selection statement will execute the first part of the selection statement and print a problem with a * operator. It will also calculate the answer by multiplying the values from the firstNumber and secondNumber lists. The result of the call will be to print 5 multiplication problems and return the number of correct answers.


The second call will pass the letter D. Based on this call, the program should select a multiplication problem. Inside the loop, the selection statement will execute the else clause since D does not equal M. As a result, the code will print a / operator and calculate the answer by dividing the firstNumber value by the secondNumber value. The result of the call will be to print 5 division problems and return the number of correct answers.