Option One : Change the Java Script as below
<script type="text/javascript">
function changeLink(){
document.getElementById("q").href.innerHTML="<a href="problem3.html"> second link </a>";
}
</script>
Option Two : change the code as below
HTML :
<body onload="changeLink()">
<div id="p">
<h1> <a id ="p1" href="linkone.html"> first link </a></h1>
</div>
<div id ="q">
<a id ="q1" href="linktwo.html"> second link </a>
</div>
JAVA SCRIPT :
<script type="text/javascript">
function changeLink(){
document.getElementById("q1").removeAttribute("href");
document.getElementById("q1").setAttribute("href","problem3.html");
}
</script>