Select & replace a random word in javascript
<p>I'd like to write a code in javascript that selects a random word from a text, and replaces it for another word.</p>

<p>Here's my code: </p>

<pre><code>var text = "dog cat apple stone";
var keyword = text[Math.floor(Math.random()*text.length)]; // select random word
var new_phrase = text.replace( keyword, "house"); // replace for other word

document.write("&lt;p&gt;" + text + "&lt;/p&gt;" );
document.write("&lt;p&gt;" + new_phrase + "&lt;/p&gt;");
</code></pre>

<p>However, this replaces a letter in the text not a word. Like this: "dog chouset apple stone"</p>

<p>How can I select a random word not a letter?</p>
