This script will change the second paragraph to "Hello World!"
But if I add a 3rd paragraph how would i have it automatically change the 3rd paragraph instead.
function myFunction() {
document.getElementsByTagName("p")[1].innerHTML = "Hello World!";
}
<p>Click the button to change the text of this paragraph.</p>
<p>This is also a paragraph.</p>
<p>This is also a paragraph.</p>
<button onclick="myFunction()">Try it</button>