Code

Ace your homework & exams now with Quizwiz!

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); }

0 1 2

If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size) move(); turnLeft(); putBall(); turnLeft(); turnLeft(); turnLeft(); move(); turnLeft();

Street 1, Avenue 3, Facing North

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?

The x coordinate of the center of the circle

Which of the following best describes the difference between the domain and path of a URL?

The domain specifies where the browser's request should be sent. The path specifies exactly what file is being requested.

What makes the following command an invalid Karel command? turnleft();

The l should be a capital L

How many times will this program print "hello"? var i = 50; while (i < 100) { println("hello"); }

This code will loop infinitely

Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); putball(); move(); move(); move(); move(); move();

This code won't run because of a syntax error

How can we improve the following program? function start() { move(); move(); move(); move(); move(); move(); move(); move(); move(); }

Use a for loop to repeat the move command

What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location? while (________) { takeBall(); }

ballsPresent()

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <p class="fire" id="title">Hello World!</p>

blue

What statement can we use inside of a loop to end it?

break

We want to print the phrase "CodeHS is the best" exactly 25 times. What kind of control structure should we use?

for loop

What kind of statement allows us to run a block code only if a certain condition is true?

if statement

What kind of statement allows us to run one block of code if one condition is true, and a separate block of code otherwise?

if/else statement

What is the proper function to call to print to the screen?

println

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) ); }

result, x, y, and MAX_NUMBER

What is the term for the value that signals the end of user input?

sentinel

Which of the following is not a valid condition to go in an if statement for Karel?

turnLeft()

What keyword do you need to use to define a variable in JavaScript?

var

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use?

while loop

What is the domain of this URL: www.example.com/home.html

www.example.com

Which of the following is not a valid value for a boolean?

yes

What is the output of the following program?

10

How many possible values can Randomizer.nextBoolean() return?

2

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); } }

20

Why does a programmer indent their code?

All of the above

In this code, how many times is the dance function called and how many times is it defined? function start() { move(); dance(); move(); move(); turnLeft(); dance(); dance(); } function dance() { turnLeft(); move(); turnLeft(); turnLeft(); move(); turnLeft(); }

Called 3 times, defined 1 time

What is generated from the following HTML code: <h1>Hello</h1> <h3>Hello</h3> <h6>Hello</h6>

Hello (Large) Hello (Medium) Hello (small)

Which of the following statements are true about styling your web pages with CSS: I. Styling with CSS is more scalable than using style= on each HTML tag that you want to style II. You can create styles with CSS that are not possible using style= on an HTML tag

I only

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); }

15 5

How many times will the following code print "hello"? for (var i = 3; i < 8; i++) { println("hello"); }

5

How many total times will Karel move in this program? function start() { move(); for (var i = 0; i < 5; i++) { move(); putBall(); } }

6

What is wrong with this for loop? for (var i = 0, i < 10, i + 1) { move(); } A. The for loop uses commas instead of semicolons B. It should say i++ instead of i + 1

A and B

What is top down design?

Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.

What is the proper operator for "not equals" in JavaScript?

!=

What symbol represents the and operator in JavaScript?

&&

Which of the following is the proper format for an HTML tag?

<h1>Content Affected by Tag</h1>

How can we check if a variable num is even?

(num % 2 == 0) will be true

What will be the value of sum after this code runs? var START = 1; var END = 4; function start(){ var sum = 0; for(var i = START; i <= END; i++){ sum += i; } }

10

How can we teach Karel new commands?

Define a new function

Which of the following is the correct way to define a turnRight function in Karel?

function turnRight() { turnLeft(); turnLeft(); turnLeft(); }

What function do you need to call to get the width of the screen?

getWidth()

What are the coordinates of the center of the window?

getWidth() / 2, getHeight() / 2

What are the coordinates of the top right corner of the screen?

getWidth(), 0

In a graphics canvas, what are the coordinates of the bottom right corner of the window?

getWidth(), getHeight()

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <p class="title">My First Paragraph</p>

green

Which of the following is a valid CSS rule?

h1 { color: blue; }

What is the proper format for a single line comment in Karel?

// This is a comment

What will the following code print to the screen?

4

What symbol do you use to do multiplication in JavaScript?

*

What symbol do you use to do division in JavaScript?

/

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; }

3 parameters go in, 1 return value comes out

Which of the following is the proper HTML code to display an image on your webpage?

<img src="https://upload.wikimedia.org/wikipedia/commons/6/62/Big_and_little_dog.jpg">

Suppose you are making a music streaming website and you want to make a page that displays a user's music library. Which of the following is the proper HTML code to create the following table:

<table border="1"> <tr> <th>Title</th> <th>Artist</th> <th>Length</th> </tr> <tr> <td>CD Jam</td> <td>Rooney Pitchford</td> <td>3:55</td> </tr> <tr> <td>Memory</td> <td>Tom Misch</td> <td>5:41</td> </tr> </table>

What is the proper way to compare if two values are equal in a boolean expression in JavaScript?

==

Why do we write functions?

All of the above

In the following code, what would be a good Postcondition to write? /* Precondition: Karel is on a spot with a tennis ball facing East * Postcondition: ... */ function getOnTop() { turnLeft(); move(); turnRight(); }

Karel ends one spot above a tennis ball facing East.

How many times will the following program print "hello"? var i = 0; while(i < 10){ println("hello"); }

This code will loop infinitely

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;

false

Suppose you have the following CSS rules: p { color: green; } .fire { color: red; } #title { color: blue; } What font color will the following HTML element have after being styled by the given CSS: <h1 class="fire">Welcome!</h1>

red

After the following code runs, what is the value of isWeekend? var isSaturday = true; var isSunday = false; var isWeekend = isSaturday || isSunday;

true

Which of the following is a good example of a proper constant variable name?

var MAX_VALUE = 100;

Suppose you have written a web page using HTML and CSS and it is hosted at the URL yourdomain.com/home.html Which of the following statements is true about which devices can view your website?

Any browser on any device will be able to view your webpage, because all browsers and devices on the Internet agree to use the same protocols for sending, receiving, and viewing webpages.

o ask the user of the program for a number, which function should you use?

Both readInt and readFloat are for numbers.

Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

For loop

In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2? // This program has Karel walk down the // row and clean up all of the tennis balls // on the way. function start() { while (frontIsClear()) { // If statement #1 if (ballsPresent()) { takeBall(); } move(); } // If statement #2 if (ballsPresent()) { takeBall(); } }

To pick up the ball that is in the last spot, if there is one

What is the purpose of using a for loop in code?

To repeat something a fixed number of times

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem. 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?

Add a break; statement after line 7 so that the program doesn't loop infinitely

Why do we use constant variables?

All of the above

Why do we use functions in Karel programs?

All of the above

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");

Hello, we are open! Sincerely, the grocery store

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);

Is it warm: true

CSS rules have a selector that defines which HTML elements the rule applies to. We've learned about the following CSS Selectors: Select by tag name Select by class name Select by id name Which of the following ranks the selectors from highest precedence to lowest precedence?

Select by id name, select by class name, select by tag name

Karel starts at Street 1 and Avenue 1, facing East. After calling the stairStep function twice, where will Karel be and what direction will Karel be facing? (assume this is a SuperKarel program and the world is 10x10 in size) function stairStep() { move(); turnLeft(); move(); turnRight(); }

Street 3, Avenue 3, Facing East

What's wrong with this code? function start() { move(); go(); go(); } function go() { move(); move(); } function go() { move(); move(); }

The go function has been defined twice

In the following code, we create a circle and add it to the screen. What is the meaning of the x variable? var x = 20; var circle = new Circle(x); add(circle);

The radius of the circle

Which of the following classifies as metadata about a webpage?

The title of the webpage

"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?

function isSuperman(isBird, isPlane){ return !isBird && !isPlane; }

Which of the following commands is a valid Karel command?

move();

What function do you need to call to ask the user of the program to enter text?

readLine

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?

var applesToBuy = readInt("How many apples would you like? ");

You are splitting up all of your apples equally between 3 people. Which statement below will calculate how many apples will be left over?

var leftOver = numApples % 3;

In the following function printThreeTimes: function printThreeTimes(word){ println(word); println(word); println(word); } What is the parameter of the function?

word

What symbol represents the or operator in JavaScript?

||

Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location? for (var i = 0; i < 3; i++) { if (ballsPresent()) { takeBall(); } else { putBall(); putBall(); } }

1

What is the result of the following HTML code: <ol> <li>Bread</li> <li>Milk</li> <li>Eggs</li> </ol>

1. Bread 2. Milk 3. Eggs

How many times will this program print "hello"? var i = 10; while (i > 0) { println("hello"); i--; }

10

In the following code, what will be the last number to print to the screen before the program finishes? for (var i = 0; i < 10; i++) { if (i % 2 == 0) { println(i); } else { println(2 * i); } }

10

How many times will the following code print "hello"? for (var i = 0; i < 8; i += 2) { println("hello"); }

4

How many times will the following program print "hello"? for (var i = 0; i < 5; i++) { println("hello"); }

5

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); }

7

What does the mystery function do? function mystery() { while (noBallsPresent()) { move(); } }

Karel moves until it is on a ball

Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs? move(); move(); turnRight(); move();

Karel will crash into a wall

Which of the following returns a random number between 1 and 10?

Randomizer.nextInt(1, 10)

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?

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

A store has 20 apples in its inventory. How can you store this information in a JavaScript variable?

var numApples = 20;

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?

var x = Randomizer.nextInt(circle.getRadius(), getWidth() - circle.getRadius()); var y = Randomizer.nextInt(circle.getRadius(), getHeight() - circle.getRadius()); circle.setPosition(x, y);

Which of the following is correct loop and a half structure?

while(true){ //code if(condition){ break; } //code }


Related study sets

BIO 156 Exam 2 Practice Questions (Book & RioLearn)

View Set

A&P2 BIO142 LAB 8: Reproductive System

View Set

PrepU: Ch. 10 Leadership, Managing and Delegating

View Set