CodeHS, Introduction to Computer Science, Final Exam, Multiple Choice
17. Choose the correct logical operator to fill in the blank in the if statement. You may assume that the variable 'age' has already been initialized.
A. &&
9. What is the difference between a for loop and a while loop?
A. A for loop repeats commands a specific number of times and a while loop repeats until a condition becomes false.
24. The difference between local variables and global variables is
A. Local variables can only be used in the function they are declared in, while global variables can be used anywhere in the code
15. What will be the output of the following program? var circle = new Circle(100); circle.setPosition(getWidth()?2, 0); circle.setColor(Color.blue); add(circle);
A. The circle is on the top with half a circle showing.
13. What will the following program do when run? var number = readLine("Enter a number: "); println("Number is: " + number);
A. The program will ask the user for a number and then will print 'Number is:' with the number they entered
19. What is the final value of the following boolean statement stored in goodNum? var num = 6; var goodNum = (num == 6) // (num != 6);
A. true
2. If x represents the area of the number line colored blue, which inequality accurately reflects the value of x?
A. x< 4
4. Karel the Dog is instructed to move forward two spaces. Then, if Karel is standing on a ball, Karel will turn left and move forward two spaces. Otherwise, Karel will turn around and move forward two spaces. Given the starting point below, where will Karel end up?
B.
23. Consider the picture below. There are two circle labelled A and B. Circle A is at position (100, 100). Which of the following choices most accurately describes circle B's position? The red lines are for reference. They cross at the center of the screen.
B. (100, 400)
22. What will be printed from the following for loop? for(var i = 0; i < 10; i += 5){ println(i); }
B. 0 5
1. Evaluate the mathematical expression 3 + 4 * 6 / 2
B. 15
6. Consider the following program code, where 'hours' is an input from the user. if(hours <= 12){ println("Good morning!"); } else if(hours< 16){ println("Good afternoon!"); } else { println("Hello!"); } Of the following choices, select the value for 'hour' that would cause this program to print "Good Afternoon!"
B. 15
18. What is the final value of the following boolean statement stored in goodNum? var num = 6; var goodNum = (num < 10) && (num > 6);
B. false
20. Consider the following function. Which of the options below correctly picks the variable that is the return value? function amountOffScreen(xPos, yPos){ var xDistOff = xPos - MAX_X; var yDistOff = yPos - MAX_Y; var total = xDistOff * yDistOff; return total; }
B. total
10. Consider the following program code: var sum = 0; for(var i = 0; i < 3; i++) { sum += i; } println(sum); What is the result of running this program code?
C. 3 is printed
14. What would be printed to the screen when the following program is run? function returnNumber(x): return x + 2; println(returnNumber(3));
C. 5
12. What is the total number of times Karel moves when the code below is run? function moveForward() { for(var I = 1; I < 5; i++) { move(); } } moveForward() moveForward()
C. 8
11. How many times would the phrase 'codeHS' be printed in the following scenario: repeat 2 times { repeat 4 times { println ("codeHS"); } }
C. 8 times.
21. Which of the following statements is the best reason for why comments are important?
C. Comments help you and other read and understand your code.
5. Which of the following describes a task effectively broken into smaller parts? I. Making a list of your favorite colors II. Throwing a dinner party by making a guest list, buying ingredients, and cooking food III. Comparing the syntax of Python and JavaScript
C. II only
25. Which of the following variables is a parameter in the function below? function mystery(a, b){ var c = 0; var d = 0; for(var i = o; i < a; i++){ c += b; d *= b; } return c + d; }
C. b
3. Twelve identical circles fit inside the rectangle as shown below. If the rectangle has a width of 32 units and a height of 24 units, what is the radius of each circle?
D. 4
8. Eliza will wear a coat if it is raining or if it is less than 50o F outside. Otherwise, Eliza will leave her coat at home. In which of the following cases will Eliza leave her coat at home?
D. It is not raining and 50oF
16. What is an event in JavaScript?
D. Something that is triggered based on the user's action
7. Which of the following successfully switches the values of the variables x and y? The var temp may be used as a temporary variable if necessary.
D. Var temp = x; x = y; y = temp;