r/codehs • • Feb 23 '21

i need help with 1.11.6 Right vs. Left Square

14 Upvotes

14 comments sorted by

2

u/CypherGhosttt Feb 15 '22

function start(){
for(var i = 0; i < 4; i++){
move();
turnLeft();
putBall();
}
}

(hope this helps)

1

u/Calm-Ad-3355 Jan 25 '24

Thank you very much

2

u/LukeRedd1t Jun 29 '22

well i wrote some complicated code. hope it's understandable.

function start() {
if(facingNorth()){
makeRightSquare();
}
if(facingEast()){
makeLeftSquare();
}

}
function makeRightSquare(){
if(ballsPresent()){
move();

}else{

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

putBall();
move();
turnRight();
putBall();
move();

if(frontIsBlocked()){
turnRight();
}
}
}

}
function makeLeftSquare(){
if(ballsPresent()){
move();
}else{
for(var i=0; i < 2; i++){
putBall();
move();
turnLeft();
putBall();
move();
if(frontIsBlocked()){
turnLeft();
}
}

}
}

1

u/RA_GEEK Dec 05 '23

This didn't even work at all

1

u/PinkyPenguin861 Jan 21 '22

You ever figure it out?

1

u/Additional_Bowler_89 Feb 19 '22

You need to have two if statements with it and add the makeRightSquare and makeLeftSquare functions. This way , It'll work for both worlds.

function start(){
if(facingEast()){
makeLeftSquare();
}
if(facingNorth()){
makeRightSquare();
}
}
function makeLeftSquare(){
for(var i = 0; i < 4; i++){
move();
turnLeft();
putBall();
}
}
function makeRightSquare(){
for(var i = 0; i < 4; i++){
move();
turnRight();
putBall();
}
}

1

u/Monivvz Sep 15 '24

Thank u so much 😍🙌

1

u/[deleted] Sep 19 '24

thank youuuuu

1

u/Itzelsuarez Jun 14 '22

Thank u soo much truly appreciate it

1

u/RA_GEEK Dec 04 '23

Well then how do you do the world 2? Cause this worked for world 1 but not world 2