Mixed Messages task

Mixed Messages Task

Hi all,

this is my first posting. This is what i came up with for the mixed messages task.

Random Cluedo with a twist Generator

One of the classic board games in the 80’s was cluedo (probably still being made I think), which would involve a random individual committing a crime with a random weapon in a random room. This program will simulate choosing the 3 cards at the start of a game of Cluedo.

The game will output: e.g.

Character - Murder weapon - Room

sample output

Cluedo crime generator!
β€œIt was Mrs. Peacock with the rope in the Billiard Room!”

const cluedoArr = [
  [
    "Miss Scarlett",
    "Colonel Mustard",
    "Mrs. White",
    "Reverend / Mr. Green",
    "Mrs. Peacock",
    "Boris Johnson",
    "the Corgi",
  ],
  [
    "the Dining Room",
    "the study",
    "the Library",
    "the Billiard Room",
    "10 Downing Street",
  ],
  ["Candlestick", "Dagger", "Lead Pipe", "Cornish Pasty", "Rope"],
];

const giveMeANumberBetweenZeroAnd = (num) => {
  const randomNumber = Math.floor(Math.random() * num);
  return randomNumber;
};

const generatePerson = () => {
  const num = giveMeANumberBetweenZeroAnd(cluedoArr[0].length);
  const person = cluedoArr[0][num];
  return person;
};

const generateRoom = () => {
  const num = giveMeANumberBetweenZeroAnd(cluedoArr[1].length);
  const room = cluedoArr[1][num];
  return room;
};

const generateWeapon = () => {
  const num = giveMeANumberBetweenZeroAnd(cluedoArr[2].length);
  const weapon = cluedoArr[2][num];
  return weapon;
};

const createMessage = (person, weapon, room) => {
  const message = `"It was ${person} with the ${weapon} in ${room}!"`;
  return message;
};

const displayMessage = (message) => {
  console.log("Cluedo crime generator!");
  console.log("-----------------------");
  console.log(message);
};

const init = () => {
  const person = generatePerson();
  const weapon = generateWeapon();
  const room = generateRoom();
  const message = createMessage(person, weapon, room);
  displayMessage(message);
};

init();
5 Likes

Hey i just came to comment my first post! I liked your solution. Great work! i tried I just came to this project and i have some doubts about it. Will you like to help me?