Pull random item from array on button click HELP

    function getValue() {
    var traits = ["Innovative", "Dynamic", "Adventurous", "Curious", "Passionate", "Liberal", "Strong", "Outspoken", "Assertive", "Atheletic", "Empathetic", "Brave", "Driven", "Hopeful", "Ambitious"];
    var random = traits[Math.floor(Math.random() * traits.length)];
    return random;
    $("#button").click(function() {

Hey guys. So all I’m trying to do is get a random array item (string) to replace button text (span id=“text”) on each button click. But I’m having some trouble with it. What am I doing wrong? Thanks!

The variable random only exists within the scope of the getValue function. Your assignment code $("#text").html(random); is outside that scope. Try calling the getValue() function to get the random string instead.

Yep, that worked haha. Thank you! :slight_smile: