Mixed Messages - Project Feedback

I have just completed the portfolio project for ‘Mixed Messages’.

I decided to implement a simple version of the popular ‘Cards Against Humanity’ game and used random numbers to pick the cards and edit the text appropriately. Any thoughts or feedback on the code below would be greatly appreciated!

All of the cards are stored in a file which is then moved into arrays for use within the program.


Codecademy (Group Project: Mixed Messages)

Cards Against Humanity in javaScript


const cards = require("./cah-cards-full.json"); // read json full containing cards

const blackCards = cards[0]["black"]; // black cards contain blanks

const whiteCards = cards[0]["white"]; // white cards are used to fill the blanks

// select a random black card and retrieve the text

const randomBlack = Math.floor(Math.random() * blackCards.length);

let text = blackCards[randomBlack]["text"];

// select a random white card and remove any full stops

const randomWhite = Math.floor(Math.random() * whiteCards.length);

let whiteText = whiteCards[randomWhite]["text"];

whiteText = whiteText.replace(".", "");

// update the black card's text and log it to the console

text = text.replace("_", `*${whiteText}*`);