gpt-4.1-mini-2025-04-14· OpenAI
WildChat-4.8M (AI2)
function randomText(text1, text2)
- User
function randomText(text1, text2)
- Assistant
Certainly! Here's an example of a simple JavaScript function named
randomTextthat takes two strings as input and returns one of them at random:function randomText(text1, text2) { // Generate a random number between 0 and 1 const random = Math.random(); // Return text1 if random is less than 0.5, otherwise return text2 return random < 0.5 ? text1 : text2; }Usage example:
console.log(randomText("Hello", "World")); // could log "Hello" or "World"Let me know if you'd like the function in a different language or any additional features!