Getting number between two values - Javascript Data Type

Javascript examples for Data Type:Number

Description

Getting number between two values

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from  w  w  w .j  a  v a  2  s.c  o  m
function myFunction(min, max) {
    return function(v) {
        return v > max ? max : (v < min ? min : v);
    };
}
var myFunc = myFunction(0, 100);
console.log(myFunc(25));
console.log(myFunc(50));
console.log(myFunc(74));
console.log(myFunc(120));
console.log(myFunc(-300));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials