From 439bcbeb5a3ead4bc3e29d577be9c654ca447630 Mon Sep 17 00:00:00 2001 From: MassFuer Date: Fri, 21 Nov 2025 17:24:37 +0100 Subject: [PATCH] lab ok without the entire dataset formatted. --- src/clue.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/src/clue.js b/src/clue.js index 58d8608ab..72e069486 100644 --- a/src/clue.js +++ b/src/clue.js @@ -2,25 +2,87 @@ // Suspects Array -const suspectsArray = []; - -// Rooms Array - -const roomsArray = []; +const suspectsArray = [ + { + firstName: "Jacob", + lastName: "Green", + occupation: "Entrepreneur", + age: 45, + description: "He has a lot of connections", + image: + "https://pbs.twimg.com/profile_images/506787499331428352/65jTv2uC.jpeg", + color: "green", + }, + { + firstName: "Doctor", + lastName: "Orchid", + occupation: "Scientist", + age: 26, + description: "PhD in plant toxicology. Adopted daughter of Mr. Boddy", + image: "http://www.radiotimes.com/uploads/images/Original/111967.jpg", + color: "white", + }, + { + firstName: "Victor", + lastName: "Plum", + occupation: "Designer", + age: 22, + description: "Billionaire video game designer", + image: + "https://66.media.tumblr.com/ee7155882178f73b3781603f0908617c/tumblr_phhxc7EhPJ1w5fh03_540.jpg", + color: "purple", + }, +]; // Weapons Array -const weaponsArray = []; +const weaponsArray = [ + { + name: "rope", + weight: 8, + }, + { + name: "knife", + weight: 8, + }, + { + name: "candlestick", + weight: 2, + }, +]; +// Rooms Array + +const roomsArray = [ + { name: "Dining Room" }, + { name: "Conservatory" }, + { name: "Kitchen" }, + { name: "Study" }, +]; // ITERATION 2 -function selectRandom() {} +function selectRandom(card) { + return card.length + ? card[Math.floor(Math.random() * card.length)] + : undefined; +} -function pickMystery() {} +console.log("random suspect is :", selectRandom(suspectsArray)); +function pickMystery() { + return { + suspect: selectRandom(suspectsArray), + weapon: selectRandom(weaponsArray), + room: selectRandom(roomsArray), + }; +} +const c = pickMystery(); +console.log("mystery card is", pickMystery()); // ITERATION 3 -function revealMystery() {} - +function revealMystery(obj) { + return `${obj.suspect.firstName} ${obj.suspect.lastName} killed Mr. Boddy using the ${obj.weapon.name} in the ${obj.room.name}!`; +} +console.log(revealMystery(c));