JSFiddle - React, Tailwind, and code Playground

by Siva Subramaniam

HTML

<div id="introduction">FusionCharts Suite XT gives you the best-looking charts in the industry — exciting animation, smart designs and rich interactivity. Show off the beautiful dashboards in your product to drive more sales, or drive adoption of the application in your organization.</div>

<div id="description">FusionCharts Suite XT comes with 1,500+ pages of exhaustive documentation having complete API and attribute definitions, integration examples and tutorial-style explanation of all the advanced capabilities, for more details visit our website. The dashboards simulate real-life business use cases and are the best place to get inspired from. And if you are stuck with a query, you don’t have to scout 3rd party forums to find an answer — just write in to our tech support and team and get an answer within 24 working hours, for more details visit our website. Implementation will be a breeze.
</div>

JavaScript

/* 
* Write code to do the following:
* Delete the text from first sentence inside the 'description' div * after the word 'industry'
* using javaScript string manipulation.
*/
var firstParagraph = document.getElementById("introduction");
if(firstParagraph !== null) {
var firstParaText = firstParagraph.innerHTML;
    //The next line finds the first index of the word 'industry' and then gets the index of the word after industry by adding the length of word industry. And then from this index it gets the substring after the first occurence of '.'. By this way all the words in first sentence after the word industry is removed.
    firstParaText = firstParaText.substr(0,firstParaText.indexOf("industry")+"industry".length)+firstParaText.substr(firstParaText.indexOf("."));
    firstParagraph.innerHTML = firstParaText;
}

/*
* Write code to do the following:
* The text inside 'description' div has multiple occurances of 
* 'for more details visit our website',
* remove all of them. 
*/
var secondParagraph = document.getElementById("description");
if(secondParagraph !== null) {
    var secondParaText = secondParagraph.innerHTML;
    //Searching and replacing the given string with empty string
    secondParaText = secondParaText.replace(/for more details visit our website/g, "");
    secondParagraph.innerHTML = secondParaText;
}