Programming with Karel pt. 2

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

What do we use control structures for in JavaScript? A. Control the flow of the program; how the commands execute. B. Start our JavaScript program C. Store information for later D. Teach Karel new commands

A. Control the flow of the program; how the commands execute.

ou need to write a program that has Karel move 6 times and then put a ball. Which control structure do you need to use? A. For loop B. While Loop C. If Statement D. If/Else statement E. one of these

A. For loop

Which of the following is an example of a 'runtime error'? I. Karel crashing into a wall II. Leaving a semicolon off the end of a command III. Using the wrong syntax in an if/else statement IV. Not closing all open brackets A. I B. I and III C. II and IV D. I-IV, all

A. I

You need to write a program that has Karel move if the front is clear, but if it isn't clear, Karel will do nothing. Which control structure do you need to use? A. For Loop B. While Loop C. If Statement D. If/Else statement E. None of these

C. If Statement

You need to write a program that has Karel put down a tennis ball if the world has dimensions of 1x1. Which control structure do you need to use? A. For Loop B. While Loop C. If Statement D. If/Else statement E. None of these

C. If Statement

Why do we use while loops in JavaScript? A. To break out of some block of code B. To do something if a condition is true C. To repeat some code while a condition is true D. To repeat something for a fixed number of times

C. To repeat some code while a condition is true

The following code contains an error. What line is it on? 1 function start() { 2 move(); 3 move(); 4 turnRight(); 5 putball(); 6 move(); 7 } 8 9 function turnRight() { 10 turnLeft(); 11 turnLeft(); 12 turnLeft(); 13 } A. line 3 B. line 4 C. line 5 D. line 9

C. line 5

Which general if statement definition is written correctly? A for(condition) { // code } B if(condition) { //code } C if(var i = 0; i < count; i++) { //code } D if false { //code }

B if(condition) { //code }

Why do we use if statements in JavaScript? A. To break out of some block of code B. To do something only if a condition is true C. To do something while a condition is true D. To repeat something for a fixed number of times

B. To do something only if a condition is true

Why do we use if/else statements in JavaScript? A. To repeat something for a fixed number of times B. To either do something if a condition is true or do something else C. To break out of some block of code D. To repeat something while a condition is true

B. To either do something if a condition is true or do something else

You need to write a program that has Karel take all the tennis balls where Karel is standing if there are any there. Karel should end up with no tennis balls on that spot. Which control structure do you need to use? A. For Loop B. While Loop C. If Statement D. If/Else Statement E. None of these

B. While Loop

What is the best way for Karel to move 10 times? A. move(); move(); move(); move(); move(); move(); move(); move(); move(); move(); B. for (var i = 0; i < 10; i++) { move(); } C. move(10); D. move10();

B. for (var i = 0; i < 10; i++) { move(); }

What does an if/else statement look like in JavaScript? A if (condition) { //code } B for (var i = 0; i < count; i++) { //code } C if (condition) { //code } if (condition) { //code } D if (condition) { //code } else { //code }

D if (condition) { //code } else { //code }

Which general while loop definition is written correctly? A while (x is true) { // code } B if (i<5) { //code } C while (var i = 0; i < count; i++) { //code } D while (condition) { //code }

D while (condition) { //code }

Why should a programmer indent their code? A. Helps show the structure of the code B. Easier for other people to understand C. Indenting is a key part of good programming style D. All of the above

D. All of the above

Which of the below are examples of control structures? (I) if (II) if/else (III) while (IV) for A. I only B. I and II only C. III and I only D. I, II, III, and IV

D. I, II, III, and IV

You need to write a program where Karel will take a ball if there is a ball present, otherwise Karel should put down a ball. Which control structure do you need to use? A. For Loop B. While Loop C. If Statement D. If/Else statement E. None of these

D. If/Else statement

Will the following program move Karel one space, pick up three tennis balls, then move forward and put down three tennis balls? function start() { move(); tennisBalls(); move(); tennisBalls(); } function tennisBalls() { for(var i = 0; i < 3; i ++) { if(noBallsPresent()){ putBall(); } else { takeBall(); } } } A. Yes, because it is using the tennisBalls() function. B. No, because the tennisBalls() function is looping the wrong number of times. C. Yes, because the move() command is being called outside of the function. D. No, because the tennisBalls() function has an incorrect if/else statement.

D. No, because the tennisBalls() function has an incorrect if/else statement.


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

chapter 1 introduction to computers and programming

View Set

Frans ASO 1 Rallye 1 Circuit Rouge woorden vertalen ex 12,13,14 p 16,17

View Set

History U1 L18 Dissent and Discontent

View Set

Chapter 22: Seizing an American Empire

View Set

Angielski. Lekcja 1. Powitania, pozdrowienia.

View Set

Prep U: musculoskeletal disorders

View Set

Organizational Behavior Chapter 1

View Set

Chapter 2: Boot process and runlevels

View Set

Chapter 17: Impact of Chronic Illness, Disability, or End of Life Care on the Child and Family

View Set

anatomy module 4- neuro of rest of brain and spinal cord

View Set