Mystery Master

Build Facts

Michael Benson

Quality Materials


This help article explains how to enter the facts of a logic puzzle into a JavaScript puzzle module. A fact is entered via the puzzle method given below. You should notice there are many variations to this method.

	this.addFact("clueNum", nounA, verb, link, [nounB], ["Name."], [initEnabled = true]);

This is the JavaScript puzzle module for the logic puzzle "Five Houses". This is the most straight-forward way to enter a fact:

	this.addFact("1", englishman, Is, With, red, "The Englishman lives in the red house.");

What makes facts so interesting is that if you correctly define the sayFact method, this method will create the text of the fact for you! In other words, if you called this method as sayFact(englishman, Is, With, red), it will return the string "The Englishman is in the red house."

Since the sayFact method is defined to return the right text for the facts of this puzzle, the facts are entered using the JavaScript given above.

Precision Craftsmanship
	this.addFact("1", englishman, Is, With, red);
	this.addFact("2", spaniard, Is, With, dogs);
	this.addFact("3", coffee, Is, With, green);
	this.addFact("4", ukrainian, Is, With, tea);
	this.addFact("5", green, Is, directlyRightOf, white);
	this.addFact("6", stamps, Is, With, snails);
	this.addFact("7", antiques, Is, With, yellow);
	this.addFact("8", house3, Is, With, milk);
	this.addFact("9", norwegian, Is, With, house1);
	this.addFact("10", sings, Is, nextTo, fox);
	this.addFact("11", gardens, Is, With, juice);
	this.addFact("12", antiques, Is, nextTo, horse);
	this.addFact("13", japanese, Is, With, cooking);
	this.addFact("14", norwegian, Is, nextTo, blue);

Please note that there are variations of addFact that allow you to easily enter more than one fact at a time. The best way to learn is to look at the existing puzzle modules to see how it's done.

Excellent Products

Note: When there are variations to a method, this is called method overload.

The sayFact Project

Because this method is so vital to dynamically creating the text of a fact, the sayFact method should probably have its own project. Someday.


This article is part of the "Build Logic Puzzles" series. The next article in the series is "Build Rules". Thank you.