Navigation:  Tutorials > Beginners Guide to Smalltalk > Programming in Smalltalk > Wiring the game together >

Prompting for a new Question

Previous pageReturn to chapter overviewNext page

And, almost finally, we need a method to prompt for a new Question object.

Question class>>promptToDistinguish: anOldAnimal from: aNewAnimal

       "Answers an instance of the receiver (a Question) that will distinguish between

       anOldAnimal and aNewAnimal. The question should be phrased such that the

       answer is 'yes' for aNewAnimal"


       | questionText |

       [questionText isNil or: [questionText isEmpty]] whileTrue: [

               questionText := Prompter prompt: ('Now, please enter a question that will answer Yes for ',

                       aNewAnimal displayString,

                       ' and No for ',

                       anOldAnimal displayString)

                       caption: 'Now, so I can learn about ', aNewAnimal displayString ].

       ^self text: questionText yes: aNewAnimal no: anOldAnimal


Once again we have to use a Prompter and check to see that a valid response is received from the player before creating the new instance.