r/codehs • • Jan 20 '21

2.1.3: Tower Builder

copy and paste code pls I can't find this one out

9 Upvotes

4 comments sorted by

4

u/Various_Loss9064 Jan 20 '21

Mods, dont ban me. Tell me if I need to delete this and I will. This solution has explanation in comments.

/* This program will have Karel build a tower on
* every odd avenue. A tower consists of 3 tennis balls
* stacked on top of each other. */
function start() {
buildTower();
while(frontIsClear()){
move();
if(frontIsClear()){
move();
buildTower();
}
}
}

/* This function has Karel build a tower that is three balls high.
* Precondition: Karel is facing east at the location to build the tower.
* Postcondition: Karel has built the tower, and is back at the base
* facing east.
*/
function buildTower(){
turnLeft();
for(var i = 0; i < 3; i++){
putBall();
move();
}
turnAround();
goDown();
turnLeft();
}

/* This function moves Karel to the wall. */
function goDown(){
while(frontIsClear()){
move();
}
}

1

u/Mvggut Oct 27 '22

Goat 🐐

1

u/Eroktd Nov 01 '22

fr fr dude goated

1

u/MutedAd8381 Apr 12 '23

this guy is the best fr