Can’t call function within keyDown or keyPress event handlers

Can’t call function within keyDown or keyPress event handlers.

 var buttonColors = ["red", "blue", "green", "yellow"];
var gamePattern = [];

$(document).on("keydown",  nextSequence);

function nextSequence() {
   var randomNum = Math.floor(Math.random() * 4);
   var randomChosenColor = buttonColors[randomNum];
   return gamePattern.push(randomChosenColor);
}