Help With Random Word Generator Code

Hello. I’m really new to Javascript so please forgive me. I want to add a simple Random Word Generator to my site. I found another post with some code that almost does what I need (included below). I feel like I’m so close to figuring this out and I’ve been banging my head against it for a week. How do I take this code and have it output text from a string to a box on my page each time the button is clicked, rather than loading a link in a new browser window. Thanks so much in advance :slight_smile:

const allUrls = [     
'google . com',     
'facebook . com',     
'cnn . com',     
'abc . com' 
]; 
 
$w.onReady(function(){     
  const randomIndex = Math.floor(Math.random() * (allUrls.length - 1));     
  $w('#button1').link = allUrls[randomIndex]; 
});
const allUrls = [ 
 'google.com', 
 'facebook.com', 
 'cnn.com', 
 'abc.com' 
]; 
 
$w.onReady(function(){ 
    $w('#button1').onClick(()=>{console.log("click");
        const randomIndex = Math.floor(Math.random() * (allUrls.length - 1)); 
        $w('#text1').text = allUrls[randomIndex]; 
    });
});

https://russian-dima.wixsite.com/meinewebsite/random-numbers-strings

Thank you so much. Works perfectly.

1 Like

@charleschopshop
No problem.
Good luck and happy coding. :stuck_out_tongue_winking_eye: (you were very close)!