Objectives

Students will be able to:

  • understand that a program can be trapped in a lop while a certain contition is true.
  • write programs using pre-condition loops.

Dr. Hey and Dr. Yo

 

Dr Hey and Dr Yo

2 doctors scream Hey! and Yo! randomly at each other.

If a doctor screams his own name, then that doctor's volume increases by 1.

The first doctor to reach the target volume of 15 is declared the winner!

Copy the Scream Code into your IDE and complete the Worksheet.

Task - Adaptation

Adapt the code such that another doctor, Dr Bro, can join the screaming competition.

Doctors can now scream 3 words randomly:

  • Hey!
  • Yo!
  • Bro!

If a doctor screams Yo! or Bro!, his volume is increased.

The first doctor whose volume reaches 15 is the winner.

No Global Challenge!

Is it possible to redesign this program so that there are no global variables?

Tags

loopvalid invalid validation check unfamiliar condition IF...THEN...ELSE WHILE...DO...END WHILEiterate