Graphing
Calculator
Math
Worksheets
Scientific
Calculator
Chart
Maker


Home
Graphing Calc
Algebra
Fun Games
Geometry
Interactive
Trigonometry
Scientific Calc
Home
Graphing Calc
Algebra
Fun Games
Geometry
Interactive
Trigonometry
Scientific Calc

Advanced Topics in Jeroo

Recursion with Custom Methods

Recursion in Jeroo

Recursion 1) Identify the base case in the code below and complete the program so that the recursion works. Start the Jeroo in the top left corner. Your objective is to complete the go() method such that the Jeroo makes its way to the flower and picks it.

method go(){
    if(isFlower(AHEAD)){
        pick();
    }
else if(isWater(AHEAD)){
    turn(RIGHT);
    hop();
    turn(RIGHT);
    hop();
//after we turned around
// call ourself again
    go();
    }
else if(isNet(AHEAD)){
//you should do this part
//do not use any kind of loop 
    }    
else{
    hop();
    go();
  }

}
Jeroo Activities for recursion
Download Island Files for these two activities
The maze below can be solved by employing recursion. Write a recursive method that takes a Jeroo to the flower. The Jeroo should then stop and turn until it is looking south.

Solution
Another maze that you should be able to solve with a recursive method.

More examples of recursive methods

method recusiveMethod() {
 	if(!isWater(AHEAD))
	   hop();
	 else{
	 	turn(RIGHT);
	recusiveMethod(); 
   }
 }  
  


method recursiveMovement(){
if(isNet(AHEAD)){
   turn(RIGHT);
   hop();
}
else{
 if(isWater(AHEAD) )
   turn(RIGHT);
else 
   hop();
   recursiveMovement();
      }
}

Recursive Activities