Problem

PostHog is an open-source product analytics suite you can self-host. Heatmaps, Recordings, Funnels and more — all in a platform where you can build your own TypeScript plugins!

function getRandomChoice (array) {
  return array[Math.floor((Math.random() * array.length) + 1)]
}

getRandomChoice(["jersey mikes", "firehouse", "subway"])
Solution

By adding 1 to the result of Math.random() * array.length, it will always be greater than 1 which means the first element in the array (jersey mikes) will never be chosen.

function getRandomChoice (array) {
  return array[Math.floor((Math.random() * array.length))]
}

getRandomChoice(["jersey mikes", "firehouse", "subway"])