Karel is so excited for New Years Day! Karel wants to build a firework. Write a program that has Karel create a firework of tennis balls.

The key in this program is to break the problem down into several smaller problems and use functions to solve each smaller problem.

1 answer

// Karel will create a firework of tennis balls

// Define a function to move Karel to the starting position
function moveToStartPosition() {
move();
turnLeft();
move();
turnRight();
}

// Define a function to place a tennis ball
function placeTennisBall() {
putBeeper();
move();
}

// Define a function to turn Karel to the right
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}

// Define a function to create a firework of tennis balls
function createFirework() {
moveToStartPosition();
for (var i = 0; i < 4; i++) {
placeTennisBall();
turnRight();
}
}

// Call the createFirework function to create the firework
createFirework();
Similar Questions
  1. Karel’s world is a racetrack, and Karel is going to run a race.Your task is to get Karel to move around the racetrack eight
    1. answers icon 1 answer
  2. Karel has gotten really into board games lately.Karel wants to build a checkerboard so that he can play board games with the
    1. answers icon 2 answers
  3. Which of the following commands is a valid Karel command?move move; move(); move() Question: 2 Karel starts at Street 1 and
    1. answers icon 1 answer
  4. Which of the following commands is a valid Karel command?move move; move(); move() Question: 2 Karel starts at Street 1 and
    1. answers icon 1 answer
more similar questions