Image

I have to edit a bit of script for a homework assignment in a class on information technology and I need some help. (The prof said we could use whatever resources.) The original script is on this page. We are supposed to edit it so that people aged 40 and under are directed to Google, and people over 40 are directed to Altavista. I added the following function, but it doesn't work and I can't figure out why:

function adult_prefs(age) {
  if (age<=40)
    window.location = "http://www.google.com"
  else
    window.location = "http://altavista.com"
}


When I try it out, it directs me to Altavista no matter what age I put in. (There is also a separate redirect for kids under 16, but that part still works fine.) So I guess it's not reading the "if" line? Is there something wrong with it? I tried running the whole script through the validator at JSLint, but all it comes up with are syntax errors (missing semicolons and {} ) that are present throughout the whole script and not just the part I edited, so that wouldn't affect the script's performance.

I can post the whole script if that would be more helpful (it's not very long), but the problem seems to just be in the part I quoted above.

Any help would be greatly appreciated. :)

EDIT: Here's the full script:

<html><head><script language="JavaScript">
<!--

function jump_to_url() {
  var age = parseInt(document.age.box.value);
  if (is_valid(age))
    if (is_adult(age))
      adult_jump()
    else
      child_jump()
  else
    window.alert("Invalid age " + age)
}

function is_adult(age){
    if (age>=16)
      return true
    else
      return false
}

function is_valid(age) {
  if (age>0 && age<120)
    return true
  else
    return false
}

function adult_prefs(age) {
  if (age<=40)
    window.location = "http://www.google.com"
  else
    window.location = "http://altavista.com"
}

function adult_jump() {
  if (document.type.selection[0].checked==true) 
    adult_prefs()
  else
    if (document.type.selection[1].checked==true)
      window.location = "http://dmoz.org"
    else
      window.alert("You must select a search tool!")
}

function child_jump() {
  if (document.type.selection[0].checked==true) 
    window.location = "http://www.askforkids.com/"
  else
    if (document.type.selection[1].checked==true)
      window.location = "http://kids.yahoo.com"
    else
      window.alert("You must select a search tool!")
}

//-->
</script></head><body>
<h1>Anytown Public Library Search Tool Selector</h1>
<form name="age"><b>Please enter your age</b> <input size="10" value="" name="box"> 
</form><b>Select a Search Tool:</b> 
<form name="type"><input name="selection" type="radio"> Web Search Engine <br><input name="selection" type="radio"> Web Directory </form>
<form name="Search"><input onclick="jump_to_url()" size="10" value="Go!" name="go button" type="button"></form>
</body></html>


EDIT 2: Problem solved! Thanks! :D