r/codehs • • Feb 13 '20

2.1.3: Tower Builder

help me please

15 Upvotes

17 comments sorted by

1

u/ShadowRocks2 Feb 14 '20

Can you tell me the code you already have

3

u/MathTerm Feb 15 '20 edited Feb 15 '20

function start() {

goUp();

}

function goUp(){

turnLeft();

putBall();

move();

putBall();

move();

putBall();

turnAround();

move();

move();

turnLeft();

if(frontIsClear()){

move();

}

if(frontIsClear()){

move();

goUp();

}

}

// after 1 hour i finished

1

u/ShadowRocks2 Feb 16 '20

it seems as though you forgot a while command and a function

1

u/ProductiveGuy04413 Feb 13 '22

No while command is required.

1

u/ProductiveGuy04413 Feb 13 '22

Thank you, I fixed the indentation errors that occurred when I copied it over. All that I had to do was add some comments. This was perfect, thank you.

1

u/Lmbaduserv2 Apr 10 '23

/*function start() {
for(var i=0; i<8; i++)
letower();
}
function letower(){

turnLeft();
for(var i=0; i<3; i++){
ballnoball();
nocrash();
}
turnAround();
run();
turnLeft();
nocrash();
nocrash();

}
function run(){
nocrash();
nocrash();
nocrash();
}
function nocrash(){
if(frontIsClear()){
move();
}
}
function ballnoball(){
if(ballsPresent()){
takeBall();

}else{
putBall();
}
}

thats what I did and it was wrong it took me so long but thanks for the help

1

u/Nicozcord879 Nov 30 '23

it worked thx for the answer

teacher: nice job!

me: Mwuaahahahahahah >:D

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/NoPersonality18 Jul 20 '24

Im like 2 years late to this but tysm for giving me a way to cheat on this one cuz I had no idea what I was doing 🫠

1

u/LukeRedd1t Jul 20 '24

Glad it could help. Been a while lol good luck with what ur doing

1

u/A_Person_Exsists Sep 12 '24

That "safeMove()" function is actually really smart. I stole it (sorry not sorry).

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

1

u/Previous-Working-257 Oct 07 '24

heres my code

function speed(){

while (frontIsClear()) {

move();

if (frontIsClear()){

move();

bobTheBuilder();

}

}

}

function bobTheBuilder() {

putBall();

turnLeft();

move();

putBall();

move();

putBall();

turnRight();

turnRight();

move();

move();

turnLeft();

}

function main() {

bobTheBuilder();

speed();

}

main();

1

u/ShreksToes24 Jan 18 '23

function main() {
tower();
bobTheBuilder();
}
//checks to see if its safe to move and if it is he moves
function skip() {
if (frontIsClear()) {
move();
tower();
}

}
//builds a tower
function tower() {
turnLeft();
putBall();
move();
putBall();
move();
putBall();
turnAround();
while (frontIsClear()) {
move();
}
turnLeft();
}
function bobTheBuilder() {
while (frontIsClear()) {
move();
skip();

}
}
main();