CodeHS Karel Answer Key 2021 [*FREE ACCESS*]


In this session, we will be showing you CodeHS Karel answers for free.

CodeHS Karel Answer Key [Commands & Definitions]

Before solving SQL related problems let us answer a few basic terms & commands you must know:

Q. The command to move in Karel
Ans: move();

Q. To place a ball
Ans: putBall();

Q. To take a ball away
Ans: takeBall();

Q. What is a street in a Karel world?
Ans: a row

Q. What is an avenue in a Karel world?
Ans: a column

Q. command to turnleft
Ans: turnLeft();

Q. command to turn right
Ans: function turnRight(){ turnleft(); turnleft(); turnleft();}

Q. What is a function
Ans: It uses known terms to create new ones.

Q. The first thing you should write when creating a script
Ans: function start(){ script }

Q. What is top-down design?
Ans: It 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.

Q. What is a code comment?
Ans: A way to give notes to the reader to explain what your code is doing.

Q. What commands does SuperKarel know that regular Karel does not?
Ans: turnAround() and turnRight()

Q. What is the best way for Karel to move 10 times?
Ans:
for (var i = 0; i < 10; i++) {
move();
}

Q. How is a general if statement definition written correctly
Ans:
if(condition) {
//code
}

Q. Why do we use if statements in JavaScript?
Ans: To do something only if a condition is true.

Q. What does an if/else statement look like in JavaScript?
Ans:
if (condition) {
//code
} else {
//code
}

Q. Why do we use if/else statements in JavaScript?
Ans: To either do something if a condition is true or do something else.

Q. Why do we use while loops in JavaScript?
Ans: To repeat some code while a condition is true.

Q. Which general while loop definition is written correctly?
Ans:
while (condition) {
//code
}

Q. What do we use control structures for in JavaScript?
Ans: Control the flow of the program; how the commands execute.

Q. Examples of control structures?
Ans:
(I) if
(II) if/else
(III) while
(IV) for

Q. 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?
Ans: If/Else statement

Q. 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?
Ans: If Statement

Q. You need to write a program that has Karel put down a tennis ball if the world has dimensions of 1×1. Which control structure do you need to use?
Ans: If Statement

Q. You need to write a program that has Karel move 6 times and then put a ball. Which control structure do you need to use?
Ans: For loop

Q. 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?
Ans: While loop

Q. Why should a programmer indent their code?
Ans:
-> Helps show the structure of the code
-> Easier for other people to understand
-> Indenting is a key part of a good programming style

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

Q. What is the purpose of using a for loop in code?
Ans: To repeat something a fixed number of times.

Q. What makes the following command an invalid Karel command? turnleft();
Ans: The l should be a capital L

 

CodeHS Karel Solved Problems

Following are few solved problems included or discussed under Karel lessons:

Q. 1.2.4: Make a Tower
Ans:
/* Tennis Ball Square
* This program has Karel place a row of 3 tennis balls
* and move up and face east.
*/
move();
turnLeft();
putBall();
move();
putBall();
move();
putBall();
move();
turnLeft();
turnLeft();
turnLeft();

 

Q. 1.2.5: Pyramid of Karel
Ans:
putBall();
move();
putBall();
move();
putBall();
turnLeft();
move();
putBall();
turnLeft();
move();
putBall();
turnLeft();
turnLeft();
turnLeft();
move();
turnLeft();
turnLeft();
turnLeft();
move();
putBall();

 

Q. 1.3.4: Slide Karel
Ans:
putBall();
move();
turnRight();
move();
putBall();
turnLeft();
move();
turnRight();
move();
putBall();
turnLeft();
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}

 

Q. 1.3.5: Fireman Karel
Ans:
turnRight();
move();
move();
move();
turnLeft();
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}

 

Q. 1.4.4: Pancakes
Ans:
makePancakes();
move();
makePancakes();
move();
makePancakes();
move();
function makePancakes(){
move();
putBall();
putBall();
putBall();
}

 

Q. 1.4.5: Mario Karel
Ans:
turnLeft();
move();
move();
move();
turnRight();
move();
collectCoins();
turnLeft();
move();
turnRight();
move();
move();
turnRight();
move();
collectCoins();
move();
turnLeft();
move();
move();
turnLeft();
move();
collectCoins();
move();
turnRight();
move();
move();
turnRight();
move();
collectCoins();
move();
move();
move();
turnLeft();
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
function collectCoins(){
takeBall();
takeBall();
}

 

Q. 1.5.4: Pancakes with Start
Ans:
function start(){
move();
makePancakes();
move();
move();
makePancakes();
move();
move();
makePancakes();
move();
}
function makePancakes(){
putBall();
putBall();
putBall();
}

 

Q. 1.15.5: Staircase
Ans:
function start(){
putBall();
while(frontIsClear()){
turnLeft();
while (ballsPresent()) {
move();
}
turnRight();
move();
createStep();
}
}
function createStep() {
turnRight();
putBall();
while (frontIsClear()) {
move();
putBall();
}
turnLeft();
}

 

Q. 2.10.6: Dizzy Karel
Ans:
function run(){
for(var i = 0; i < 32; i++){
turnLeft();
}
}

 

Q. 2.4.6 Digging Karel
Ans:
buryBall();
move();
buryBall();
move();
buryBall();
move();function buryBall(){
move();
move();
turnLeft();
turnLeft();
turnLeft();
move();
move();
move();
turnLeft();
putBall();
turnLeft();
move();
move();
move();
turnLeft();
turnLeft();
turnLeft();
}

 

Q. 2.16.4: Diagonal
Ans:
//This program has karel lay a diagonal row of tennis balls. However, the indenting is all wrong.
function start(){
while(frontIsClear()){
putBall();
move();
turnLeft();
move();
for(var i = 0; i < 3; i++){
turnLeft();
}
}
putBall();
}

 

Q. 2.5.5: Digging Karel with Start
Ans:
function start(){
move();
buryBall();
move();
buryBall();
move();
buryBall();
}function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
function buryBall() {
move();
turnRight();
move();
move();
move();
putBall();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
move();
}

 

Q. 2.17.6 Checkboard Karel
Ans:
start();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
LEEF();function start(){
}function LEEF(){
turnLeft();
move();
move();
move();
move();
move();
move();
move();
turnLeft();
}

 

Q. 2.14.4: Random Hurdles
Ans:
function start() {
//This makes Karel move to all the hurdles
for (var i = 0; i < 13; i++) {
if (frontIsBlocked()) {
jumpHurdle();
} else {
move();
}
}
}function jumpHurdle() {
//This makes Karel jump over the hurdles
turnLeft();
move();
turnRight();
move();
turnRight();
move();
turnLeft();
}

 

Q. 2.20.3: Planning
Ans:
//This is going to be the function that decipher/tells Karel what to do
function start(){
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}//This will make tower build a tower when said.
function makeTower(){
putBall();
move();
putBall();
move();
putBall();
}//Not using Ultra Karel or SuperKarel this is what you should do.
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}

 

Q. 2.18.1: Fetch
Ans:
function start() {
turnLeft();
move4();
turnRight();
move2();
takeBall();
move();
turnRight();
move4();
turnLeft();
move3();
gP();
move3();
move3();
gP();
putBall();
}
//allow move karel 4 times
function move4(){
move();
move();
move();
move();
}function move2(){
move();
move();
}function gP(){
turnLeft();
turnLeft();
}function move3(){
move();
move();
move();
}

 

Q. 2.18.2: Racing Karel
Ans:
// This program will have Karel run around the racetrack 8 times.
function start(){
for(var i = 0; i < 32; i++){
setBall();
runToWall();
turnLeft();
}
}
function setBall(){
putBall();
}
function runToWall(){
while (frontIsClear()){
move();
}
}

 

Q. 2.18.4: Super Cleanup Karel
Ans:
//3 functions made 1 start
function start(){
ballsTaken();
while(leftIsClear()){
endUpFacingEast();
ballsTaken();
if(rightIsClear()){
endUpFacingWest();
ballsTaken();
}else{
turnAround();
}
}
}
function ballsTaken(){
if(ballsPresent()){
takeBall();
}
while(frontIsClear()){
move();
if(ballsPresent()){
takeBall();
}
}
}
function endUpFacingEast(){
turnLeft();
move();
turnLeft();
}
function endUpFacingWest(){
turnRight();
move();
turnRight();
}

 

Q. 2.13.6: Big Tower
Ans:
function start(){
faceNorth();
buildTower();
putBall();
}//This function make Karel face north is Karel is facing west.
function faceNorth(){
if(facingWest()){
turnRight();
}
if(facingEast()){
turnLeft();
}if(facingSouth()){
turnLeft();
turnLeft();
}
}
//This function makes Karel put the tennis balls up to the top of the “world”.function buildTower(){
while(frontIsClear()){
putBall();
move();
}
}

 

Q. 2.9.4: The Two Towers + SuperKarel
Ans:
function start(){
//Karel will build two towers
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}
//This function will be used whenever Karel is supposed to build a tower
function makeTower() {
putBall();
move();
putBall();
move();
putBall();
}

 

Q. 2.20.4: Pseudocode
Ans:
//Don’t copy this MAKE your own
Milestone 1:
First to build a tower:
Turn left
Then place a for loop:
putBall();
move();
putBall();
move();
putBall();
}
Milestone 2:
To come down:
Turn right //Because I am using “basic” Karel I have to make a function for that.
repeat 3 times
move
Turn left
}
Milestone 3:
Make function for make tower
//which is what the loop will be
putBall();
move();
putBall();
move();
putBall();
}
Milestone 4:
Make another function for basic Karel to turn Right
turnLeft();
turnLeft();
turnLeft();
}
Milestone 5:
Debug and run

 

Q. 2.20.5: Create your UltraKarel
Ans:
function Twenty(){
paint(Color.red);
move();
paint(Color.orange);
move();
paint(Color.yellow);
move();
paint(Color.green);
move();
paint(Color.cyan);
move();
paint(Color.blue);
move();
paint(Color.purple);
move();
paint(Color.gray);
move();
paint(Color.white);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.orange);
move();
paint(Color.yellow);
move();
paint(Color.green);
move();
paint(Color.cyan);
move();
paint(Color.blue);
move();
paint(Color.purple);
move();
paint(Color.gray);
move();
paint(Color.white);
move();
paint(Color.black);
}function start(){
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
}

 

Karel Challenge Unit Test Answers

Following are the important questions and answers that we think can be asked again in the upcoming exam:

Q. Which of the following commands is a valid Karel command?
Ans: move();

Q. What makes the following command an invalid Karel command?
Ans: The l should be a capital L

Q. Which of the following is the correct way to define a turnRight function in Karel?
Ans:
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}

Q. Why do we use functions in Karel programs?
Ans: All of the above

Q. 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 10×10 in size)
Ans: Street 1, Avenue 3, Facing North

Q. 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 10×10 in size)
Ans: Street 3, Avenue 3, Facing East

Q. In this code, how many times is the dance function called and how many times is it defined?
Ans: Called 3 times, defined 1 time

Q. What’s wrong with this code?
Ans: The go function has been defined twice

Q. How many total times will Karel move in this program?
Ans: 6

Q. What is wrong with this for loop?
Ans: I and II

Q. What is the proper format for a single-line comment in Karel?
Ans: // This is a comment

Q. What does the mystery function do?
Ans: Karel moves until it is on a ball

Q. Which of the following is not a valid condition to go in an if statement for Karel?
Ans: turnLeft()

Q. 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?
Ans: 1

Q. What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?
Ans: ballsPresent

Q. Why does a programmer indent their code?
Ans: All of the above

Q. How can we teach Karel new commands?
Ans: Define a new function

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

Q. Karel starts at Street 1, Avenue 1, facing East in a 5×5 world. What will happen after this code runs?
Ans: Karel will crash into a wall

Q. Karel starts at Street 1, Avenue 1, facing East in a 5×5 world. What will happen after this code runs?
Ans: This code won’t run because of a syntax error

Q. What is top-down design?
Ans: 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.

Q. How can we improve the following program?
Ans: Use a for loop to repeat the move command

Q. In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?
Ans: To pick up the ball that is in the last spot, if there is one

Q. In the following code, what would be a good Postcondition to write?
Ans: Karel ends one spot above a tennis ball facing East.

Q. What is the purpose of using a for loop in code?
Ans: To repeat something a fixed number of times

 

About CodeHS Karel

CodeHS Karel Answers Key

Karel the Dog is completely designed for beginners to learn and code easily. It works just like giving commands to a dog. It mainly teaches fundamental concepts like commands & functions.

 

>> Check CodeHS Answers For Every Topic Here <<

That’s it…

We hope you are able to find CodeHS Karel answer key by browsing with us. If it helps please share it with your friends. Thank you!


2 thoughts on “CodeHS Karel Answer Key 2021 [*FREE ACCESS*]”

  1. Apprecіating the time and effort you put into your website and in-depth informatіon уou bought for answering CodeHS Karel topics.
    It’ѕ great to come acroѕs a blog every once in a whіle that isn’t the same old rehashed information. Exсellent read!
    I’ve saѵed your site and I’m adding your RSS feeds to
    my Google account.

    Reply

Leave a Comment

Sorry! Copy-paste disabled.