Actually there are three
p
elements. Try
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>hi</p>
<p>hello</p>
<p>hi</p>
<script>
var arr = document.getElementsByTagName("p");
for (var x = 0; x < arr.length; x++) {
arr[x].innerHTML = "Hi there " + arr[x].textContent;
}
</script>
</body>
</html>