We have developed a formal model of certain types of riddles, and implemented it in a computer program, JAPE, which generates simple punning riddles. In order to test the model, we evaluated the behaviour of the program, by having 120 children aged eight to eleven years old rate JAPE-generated texts, human-generated texts, and non-joke texts for "jokiness" and funniness. This confirmed that JAPE's output texts are indeed jokes, and that there is no significant difference in funniness or jokiness between JAPE"s most comprehensible texts and published human-generated jokes.