I am new to javascript, and I am making a website with php but I can't get the javascript part to work the way I want it to.

It is very simple, I am making a part of a website (where users are logged in) where users takes exams. In php I already have the query for the database and I already have extracted their exam number (1,2,3,4,ect..) on the variable $exam. I want javascript to check their current exam (which I provided with php on the code below) and do something depending on the exam number they clicked, if is below, above, or if is the exam number they are on.

Now, remember I know nothing about javascript so I tried to write the code below based on my knowledge of php. This is what I wrote:

<script>
function exval(){
var examlinks = document.getElementByTagName('a');
var examname = examlinks.getAttribute('name');
if(examname.value > "<?php echo "$exam" ?>");
alert("You are not on this exam yet!");
else if(examname.value < "<?php echo "$exam" ?>");
alert("You already took this exam");
else if(examname.value == "<?php echo "$exam" ?>");
alert("This is your exam"); // I want it to actually take them to their link in here
return exval();
}
</script>

the php part:

<?php
if (($exam >= 1) && ($exam <= 10)) {
echo "
<a href=\"#\" name=\"1\" onclick=\"exval()\">Exam 1</a>
<br />
<a href=\"#\" name=\"2\" onclick=\"exval()\">Exam 2</a>
<br />
<a href=\"#\" name=\"3\" onclick=\"exval()\">Exam 3</a>
Ect...

Obviously the code above (javascript) doesn't do anything but that's because I don't know what I am doing, it's probably a dumb mistake but what I am trying to do is to give you an idea of what I am trying to accomplish.