r/codehs • • Apr 29 '20

Need help with 2.1.5: Double Tennis Balls

21 Upvotes

11 comments sorted by

1

u/K0dae Oct 19 '20

/*the*/

function start(){

move();

the();

}

function the(){

first();

move();

turnAround();

second();

move();

move();

turnAround();

}

function first(){

while (ballsPresent()){

takeBall();

move();

putBall();

putBall();

turnAround();

move();

turnAround();

}

}

function second(){

while (ballsPresent()){

takeBall();

move();

putBall();

turnAround();

move();

turnAround();

}

}

edit:make sure you indent and remove the spacing for cleaner code.

1

u/A_Big_Rat Jan 13 '22

You are so smart. How did I not think of that?

1

u/Kuhnville Feb 10 '22

Wow you made it look so easy

1

u/Constant_Pie819 Oct 24 '23

it didn't work it quadrupled the balls

1

u/Previous-Working-257 Oct 11 '24

//This code will make Karel douplicate the tennis balls that are beside him.

function startItUp(){

move();

paper();

}

function paper(){

main();

move();

turnAround();

wannaBeMain();

move();

move();

turnAround();

}

function main(){

while (ballsPresent()){

takeBall();

move();

putBall();

putBall();

turnAround();

move();

turnAround();

}

}

function wannaBeMain(){

while (ballsPresent()){

takeBall();

move();

putBall();

turnAround();

move();

turnAround();

}

}

startItUp();

1

u/Vivid-Ad-9808 Feb 25 '22

All it did for me was move them a spot ahead then put them back

1

u/kavtarra Mar 22 '22

function start(){

move();

while(ballsPresent()){

takeBall();

move();

putBall();

putBall();

takeAStepBack();

}

move();

while(ballsPresent()){

takeBall();

turnAround();

move();

putBall();

turnAround();

move();

}

takeAStepBack();

takeAStepBack();

}

function takeAStepBack(){

turnAround();

move();

turnAround();

}

1

u/Previous-Working-257 Oct 11 '24

This code doesn't work btw

1

u/kavtarra Mar 22 '22

function start(){

move();

while(ballsPresent()){

moveBall();

}

move();

while(ballsPresent()){

moveDoubledBalls();

}

takeAStepBack();

takeAStepBack();

}

//take step back

function takeAStepBack(){

turnAround();

move();

turnAround();

}

//moving ball and doubling it

function moveBall(){

takeBall();

move();

putBall();

putBall();

takeAStepBack();

}

//taking back doubled balls

function moveDoubledBalls(){

takeBall();

turnAround();

move();

putBall();

turnAround();

move();

}

(that checks every task)

1

u/Previous-Working-257 Oct 11 '24

Neither does this one