JavaScript : Repetition Statements III

 Objectives 

  1. To recognize which type of loop is appropriate to use in various situations;
  2. To correctly nest loops in order to complete the task in the most efficient way.

 Your Task, Your Challenge 

Le robot transporteur de repas

Write your code so that the robot delivers all the meals from the kitchen to the school.

You must write your code so that the robot delivers all the meals from the kitchen to the school. The number of meals per day varies, but there is always at least one. The number of meals that will fit in the van is unknown and may vary from one van to another. At the start, the van is empty, the doors are closed, and it is located near the school. This is where it should be located at the end of your program.

The robot can carry out 3 actions:

  1. go ('where'); where 'where' or is either 'kitchen' or 'school';
  2. vanMeal ('what'); where 'what' refers to the 'loading' into or 'unloading' from the van of one meal at a time;
  3. vanDoors ('what'); where 'what' can be 'open' or 'close'.

The robot can also perform 3 tests:

  1. vanEmpty () tests whether the van is completely empty;
  2. vanFull () tests whether the van is completely full and therefore cannot accept any more meals;
  3. atLeast1MealInKitchen () tests if there is at least one meal available on the kitchen shelves.

 Nested repetitions 

As you can see, in this exercise, you will need to use several repetition statements:

  • - 1 to make the trips;
  • - 1 to load the van;
  • - 1 to unload the van.

You must put the repetitive tasks in the correct order to succeed in this exercise.

Good luck!

Back