Computer Science Principles Test prep review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How many parameters go into the function sum, and how many return values come out of the function sum? function sum(first, second, third){ var result = first + second + third; println(first); println(second); println(third); return result; } a.)3 parameters go in, 1 return value comes out b.)3 parameters go in, 3 return values come out c.)1 parameter goes in, 4 return values come out d.)1 parameter goes in, 1 return value comes out

a

In the following code: var size = 20; var x = 100; var y = 200; var ball = new Circle(size); ball.setPosition(x, y); What is the meaning of the x variable? a.)The x coordinate of the center of the circle b.)The x coordinate of the left edge of the circle c.)The radius of the circle d.)The position of the circle

a

What is printed by the following program? function product(x, y){ return x * y; } function difference(x, y){ return x - y; } function start(){ var x = 2; var y = 5; var value1 = product(x, y); var value2 = difference(y, x); var result = difference(value1, value2); println(result); } a.)7 b.)-7 c.)13 d.)-13

a

What is printed by the following program? var isRaining = false; var isCloudy = false; var isSunny = !isRaining && !isCloudy; var isSummer = false; var isWarm = isSunny || isSummer; println("Is it warm: " + isWarm); a.)Is it warm: true b.)Is it warm: false c.)Is it warm: yes d.)Is it warm: no

a

What is printed by the following program? var numApples = 10; var numOranges = 5; if(numApples < 20 || numOranges == numApples){ println("Hello, we are open!"); } else { println("Sorry, we are closed!"); } println("Sincerely, the grocery store"); a.)Hello, we are open! Sincerely, the grocery store b.)Sorry, we are closed! Sincerely, the grocery store c.)Hello, we are open! d.)Sorry, we are closed! e.)Sincerely, the grocery store

a

We want to position a Circle circle on our canvas to be at a random position, but we want to keep the entire shape on the screen. Which of the following will accomplish this? a.)var x = Randomizer.nextInt(0, getWidth() - circle.getRadius()); var y = Randomizer.nextInt(0, getHeight() - circle.getRadius()); circle.setPosition(x, y); b.)var x = Randomizer.nextInt(circle.getRadius(), getWidth() - circle.getRadius()); var y = Randomizer.nextInt(circle.getRadius(), getHeight() - circle.getRadius()); circle.setPosition(x, y); c.)var x = Randomizer.nextInt(0, getWidth()); var y = Randomizer.nextInt(0, getHeight()); circle.setPosition(x, y); d.)var x = Randomizer.nextX(); var y = Randomizer.nextY(); circle.setPosition(x, y);

b

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use? a.)for loop b.)while loop c.)loop and a half d.)infinite loop

b

What are the coordinates of the center of the window? a.)getWidth(), getHeight() b.)getWidth() / 2, getHeight() / 2 c.)getHeight() - getWidth(), getWidth() - getHeight() d.)getHeight() / 2, getWidth() / 2

b

What is printed by the following program? function printNumbers(two, one, zero){ println(two); println(one); println(zero); } function start(){ var zero = 0; var one = 1; var two = 2; printNumbers(zero, one, two); } a.) 2 1 0 b.) 0 1 2 c.) zero one two d.) two one zero

b

What is the last thing printed by the following program? var start = 30; var stop = 10; for(var i = start; i >= stop; i-=5){ if(i % 2 == 0){ println(i * 2); } else { println(i); } } a.)10 b.)20 c.)30 d.)60

b

What is the output of the following program? function start(){ var x = 5; sumTo(x); println(x); } function sumTo(num){ var sum = 0; for(var i = 0; i <= num; i++){ sum += i; } println(sum); } a.) 5 15 b.) 15 5 c.) 5 d.) 15 e.) none, there is a syntax error

b

What is the output of the following program? var result = 0; var max = 5; for(var i = 0; i < max; i++){ result += i; } println(result); a.)15 b.)10 c.)0 d.)12345

b

What is the value of the boolean variable canVote at the end of this program? var age = 17; var isCitizen = true; var canVote = age >= 18 && isCitizen; a.)true b.)false c.)yes d.)none, there is a syntax error in this code

b

"It's a bird! It's a plane! No, it's Superman!" We want to write a function isSuperman that takes in two parameters isBird and isPlane and returns true if it is in fact Superman, and false otherwise. If it's not a bird and it's not a plane, it must be Superman. Which of the following functions is the correct implementation of isSuperman? a.)function isSuperman(isBird, isPlane){ return isBird || isPlane; } b.)function isSuperman(isBird, isPlane){ return !isBird || !isPlane; } c.)function isSuperman(isBird, isPlane){ return !isBird && !isPlane; } d.)function isSuperman(isBird, isPlane){ return isBird && isPlane; }

c

1 var SECRET_PASSWORD = "karel"; 2 3 function start(){ 4 while(true){ 5 var password = readLine("Enter your password: "); 6 if(password == SECRET_PASSWORD){ 7 println("You got it!"); 8 } 9 println("Incorrect password, please try again."); 10 } 11 } Which of the following will fix this program? a.)Change the true in line 4 to be password != SECRET_PASSWORD so that the program doesn't loop infinitely b.)Change the true in line 4 to be password == SECRET_PASSWORD so that the program doesn't loop infinitely c.)Add a break; statement after line 7 so that the program doesn't loop infinitely d.)Put line 9 inside of an else statement

c

A store has 20 apples in its inventory. How can you store this information in a JavaScript variable? a.)var numApples == 20; b.)20 = numApples; c.)var numApples = 20; d.)var num apples = 20;

c

In the following code: var MAX_NUMBER = 10; function sum(x, y){ var result = x + y; //Point A return result; } function start(){ var num1 = Randomizer.nextInt(0, MAX_NUMBER); var num2 = Randomizer.nextInt(0, MAX_NUMBER); println( sum(num1, num2) ); } Which variables exist at point A? In other words, which variables are in scope at point A? Which variables could you type at point A and the program would still work? a.)result only b.)result, x, and y c.)result, x, y, and MAX_NUMBER d.)result, num1, num2, and MAX_NUMBER e.)result, x, y, num1, num2, and MAX_NUMBER

c

You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over? a.)var leftOver = numApples / 3; b.)var leftOver = 3 / numApples; c.)var leftOver = numApples % 3; d.)var leftOver = 3 % numApples;

c

You want to read input from the user to know how many apples they would like to buy. Which statement should you use to read in a number from the user? a.)var applesToBuy = readLine("How many apples would you like? "); b.)var applesToBuy = println("How many apples would you like? "); c.)var applesToBuy = readInt("How many apples would you like? "); d.)var applesToBuy = nextInt("How many apples would you like? ");

c

How many times will the following program print "hello"? var i = 0; while(i < 10){ println("hello"); } a.)10 b.)11 c.)9 d.)This code will loop infinitely

d

In a graphics canvas, what are the coordinates of the bottom right corner of the window? a.)0, 0 b.)0, getWidth() c.)getHeight(), getWidth() d.)getWidth(), getHeight()

d

In the following function printThreeTimes: function printThreeTimes(word){ println(word); println(word); println(word); } What is the parameter of the function? a.)printThreeTimes b.)function c.)println d.)word

d

The following program should draw a circle on the screen 1 function start(){ 2 var circle = new Circle(40); 3 circle.setPosition(getWidth() / 2, getHeight() / 2); 4 circle.setColor(Color.blue); 5 } But when we run this code, we don't see the circle. What is missing from our start function? a.)We never set the circle's radius. We need to add the line circle.setRadius(40); After line 4 b.)We are setting the position of the ball to be off the canvas. We need to change line 3 to be circle.setPosition(0, 0); c.)We are creating the circle incorrectly. We need to specify the width and height. We need to change line 2 to be var circle = new Circle(40, 40); d.)We create the circle and position it correctly on the screen, but we never add it to the screen. We need to add the line add(circle); after line 4

d

We want to print the phrase "CodeHS is the best" exactly 25 times. What kind of control structure should we use? a.)if statement b.)while loop c.)break statement d.)for loop

d

Why do we write functions? a.)Make our code easier to understand by giving a readable name to a group of instructions b.)Avoid writing repeated code c.)Make our code reusable d.)All of the above

d


संबंधित स्टडी सेट्स

Chapter 6- dissociative disorders

View Set

Chapter 5, 6,7 and 8 midterm 2 business 100

View Set

Personal Fitness: Types of Muscles

View Set

Professional Nursing Concepts I - Final Review

View Set

CMSC 447 - Software Engineering Midterm

View Set

Hemolytic Disease of the Newborn

View Set