(JavaScript) min/max related question

DFORMS

New Member
This is my first post here, new member!

Trying my best to learn JavaScript using some online tutorials : s Anyways, ive been having problems with the min/max embed in a function. I want it to return the biggest or smallest # depending on if i use min or max. I got it to work with this code :

Code:
<script language="javascript">
<!--

var a=13;
var b=37; 

document.write(Math.min(a, b) + " -");  //-

// -->
</script>

But i need to use a function to return the #. Right now this is what ive got :

Code:
<script language="javascript">
<!--

function send_min ()
{
  var a=13
  var b=37
  
  result = Math.min(a, b);  
  return result
} 

// -->
</script>

Of crouse its not working...Can anyone help me out? Yes i'm a newb at JavaScript.

Thanks!
 
Last edited:

leroy30

New Member
Here ya go:

<script language="javascript">
<!--

function send_min (a, b)
{
return Math.min(a, b);
}

// -->
</script>

It probably wasn't working because you didn't declare result as a variable. =)
 

leroy30

New Member
Oh, by the way - you wouldn'y really need a function for this as math.min already does the job. Functions would generally be a combination of methods instead of just one method but as you say you are just learning ;)

Good luck!
 
Top