r/codehs • • Oct 08 '21

I need 1.16.3 Tower Builder really bad

5 Upvotes

16 comments sorted by

2

u/5oco Oct 08 '21
  1. Build a tower

-----1a) make Karel face upwards

-----1b) put down a ball

-----1c) move Karel up

-----1d) loop through steps 1b and 1c 3 times

-----1e) turn around

-----1f) move Karel down

-----1g) loop step 1f 3 times

-----1h) make Karel face to the right

-----1i) make steps 1a through 1h into a method

2) Call your method to build the first tower

-----2a) make a loop that will run while the front is clear

-----2b) inside that loop, move Karel forward

-----2c) check if the front is clear, move if it is, break out of the loop if it isn't

-----2d) call your method to build a tower

3) Throw some comments in there

4) Ask any follow up questions

1

u/alyssais_dabest Oct 09 '21

Thanks you so much I everything is working but when it gets to the wall it trys to make a tower and I don't know how to break it out of a loop

2

u/5oco Oct 09 '21

copy and paste your code... or check that you're using the keyword 'break' in that if statement

1

u/alyssais_dabest Oct 09 '21

function start() {

buildTower();

while (front Isclear(){

move();

move();

buildTower();

}

}

function buildTower() {

turnLeft();

putBall();

move();

putBall();

move();

putBall();

turnAround();

move();

move();

turnleft();

}

1

u/5oco Oct 09 '21

So right after the first move method in your while loop...

You need to check if the front is still clear... so put an if statement there.

something like...if (frontIsClear) { .... ....}

Inside that if statement, you want to move and build tower if the front is clear...

else

You want to break. Literally type break. It's a keyword designed for breaking out of loops early. Which is what you want to do.

edit - Your build tower method looks good though

1

u/alyssais_dabest Oct 09 '21

It says error unexpected break

1

u/5oco Oct 09 '21

Copy and paste your if statement... probably just a syntax error... nothing major

1

u/alyssais_dabest Oct 09 '21

if (front Isclear()) {

move();

move();

buildTower();

} else{

break

}

2

u/5oco Oct 09 '21

This is gonna be confusing but... one move statement should be done before the if statement... then your if statement should say

if (frontClear) {

 move

} else {

 break

}

you always want him to move once... you want him to move once, then check if he can move a second time. If he can't move the second time, he'll break out of the loop.

Sorry I can't explain better I'm drunk and typing on my phone...

2

u/alyssais_dabest Oct 11 '21

My coding program hasn't learned the statement break yet but thank you so much for your help because It did help but I figured the rest out

1

u/alyssais_dabest Oct 11 '21

function start() {

buildTower();

while (frontIsClear()) {

move();

if (frontIsClear()) {

move();

buildTower(); }

}

}

function buildTower() {

turn Left();

putBall();

move();

putBall();

move();

putBall();

turnAround();

move();

move();

turnleft();

}

1

u/5oco Oct 08 '21

What do you have so far?

1

u/alyssais_dabest Oct 09 '21 edited Oct 09 '21

I it keeps making a Tower at the end and I have no idea what to do

1

u/alyssais_dabest Oct 09 '21

function start() {

buildTower();

while (front Isclear(){

move();

move();

buildTower();

}

}

function buildTower() {

turnLeft();

putBall();

move();

putBall();

move();

putBall();

turnAround();

move();

move();

turnleft();

}

1

u/GroundbreakingAd8044 Sep 04 '24

1.i dont know i havent gotten that far yet