var randomColor = function () { var colors = ['red', 'blue', 'black', 'white', 'green', 'yellow', 'purple']; var rndColor = Math.floor(Math.random() * colors.length); return colors[rndColor]; }; alert(randomColor());