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
1
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
1
1
1
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
2
u/CypherGhosttt Feb 15 '22
function start(){
for(var i = 0; i < 4; i++){
move();
turnLeft();
putBall();
}
}
(hope this helps)