JavaScript doesn't differentiate between variables of different data types and mixing them up can be troublesome, so a good idea is to add prefixes to variable names, like a for array, s for string, n for number(?), and int for integer (whole number).
Sometimes the random generator returns Undefined. I do not know why. The script I studied and based this off of just has an if statement that rerolls undefined outcomes. Hopefully how I've done it is OK; nothing bad seems to be happening in testing.