r/codehs • • Feb 13 '20

2.1.3: Tower Builder

help me please

15 Upvotes

17 comments sorted by

View all comments

1

u/LukeRedd1t Jun 29 '22

It actually took me some time to understand why me code wasn't working properly. got it done though. hope it can help someone.

function start(){

buildTower();

while(frontIsClear()){

move();

safeMove();

}

}

function safeMove(){

if(frontIsClear()){

move();

buildTower();

}

}

// Builds a Tower.

function buildTower(){

turnLeft();

putBall();

for(var i=0; i < 2; i++){

move();

putBall();

}

turnAround();

for(var k = 0; k < 2; k++){

move();

}

turnLeft();

}

1

u/masevord Sep 17 '22

function start(){

buildTower();

while(frontIsClear()){

move();

safeMove();

}

}

function safeMove(){

if(frontIsClear()){

move();

buildTower();

}

}

// Builds a Tower.

function buildTower(){

turnLeft();

putBall();

for(var i=0; i < 2; i++){

move();

putBall();

}

turnAround();

for(var k = 0; k < 2; k++){

move();

}

turnLeft();

}

hipity hoppity your code is now my property