console.log(truncate('The quick brown fox jumps over the lazy dog', 6));
console.log(truncate('The quick brown fox jumps over the lazy dog', 4));
console.log(truncate('The quick brown fox jumps over the lazy dog', 8));

function truncate(str,pos)
{
    var temp = str.split(' ');
    var emp = []
    for(var i =0 ;i<pos ; i++)
    {
       emp.push(temp[i]);
    }
    return emp.join(' ');
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: