JSFiddle - React, Tailwind, and code Playground
JavaScript
var colors = ['red', 'green', 'white', 'yellow', 'blue'];
var nationalities = ['english', 'swedish', 'danish', 'norwegian', 'german'];
var beverages = ['tea', 'coffee', 'milk', 'beer', 'water'];
var cigars = ['pall mall', 'dunhill', 'blend', 'blue masters', 'prince'];
var pets = ['dog', 'bird', 'cat', 'horse', 'fish'];
var houses = [
null,
{color: '', nationality: 'norwegian', beverage: '', cigar: '', pet: ''},
{color: 'blue', nationality: '', beverage: '', cigar: '', pet: ''},
{color: '', nationality: '', beverage: 'milk', cigar: '', pet: ''},
{color: '', nationality: '', beverage: '', cigar: '', pet: ''},
{color: '', nationality: '', beverage: '', cigar: '', pet: ''}
];
var permutations;
function clue1() {
// The Englishman lives in the house with red walls.
var r = false;
for (let h = 1; h <= 5; h++) {
if ((houses[h].nationality === nationalities[0]) && (houses[h].color === colors[0])) {
r = true;
break;
}
}
return r;
}
function clue2() {
// The Swede keeps dogs.
var r = false;
for (let h = 1; h <= 5; h++) {
if ((houses[h].nationality === nationalities[1]) && (houses[h].pet === pets[0])) {
r = true;
break;
}
}
return r;
}
function clue3() {
// The Dane drinks tea.
var r = false;
for (let h = 1; h <= 5; h++) {
if ((houses[h].nationality === nationalities[2]) && (houses[h].beverage === beverages[0])) {
r = true;
break;
}
}
return r;
}
function clue4() {
// The house with green walls is just to the left of the house with white walls.
var r = false;
for (let h = 1; h <= 4; h++) {
if ((houses[h].color === colors[1]) && (houses[h + 1].color === colors[2])) {
r = true;
break;
}
}
return r;
}
function clue5() {
// The owner of the house with green walls drinks coffee.
var r = false;
for (let h = 1; h <= 5; h++) {
if ((houses[h].color === colors[1]) && (houses[h].beverage === beverages[1])) {
r = true;
break;
}
}
return r;
}
function clue6() {
// The man who smokes Pall Mall keeps...