tags:

views:

33

answers:

2

I need to show if answer = >2.80

  var panel; 
    if (routeNodes.length > 0 && (panel = document.getElementById('distance')))    
    {               
        panel.innerHTML = Number((dist/1609.344).toFixed(1)).toFixed(2)
                        + " miles = £" 
                        + Number((((dist/1609.344 - 1) * 1.20) + 2.80).toFixed(1)).toFixed(2);  
    }

if < 2.80 then show 2.80

A: 
var var1 = 10;
var var2 = 5;
var minimum = Math.min( var1, var2 );
var maximum = Math.max( var1, var2 );
// minimum now equals 5;
// maximum now equals 10;

A reference on the Math object

meouw
how would i right that?var panel; if (routeNodes.length > 0 }???
Tuffy G
Oops, I'm sorry Math.min was the wrong way to go - Anurag gets it right with Math.max
meouw
A: 

Ue functions instead of directly adding output to innerHTML.

function getDistance(input, minimum) {
    var miles = f(input);
    return Math.max(miles, minimum);
}

var string = getDistance(someValue, 2.80) + ' miles -- ' + getDistance(someValue, 2.80)
panel.innerHTML = string;
Anurag
the whole page works if i do it my way. if i dont put my output to innerHTML then it wont work at all. i've got a gmap in the background and i'm working on top of that. click 1 street, then click the other, it shows miles and price on top
Tuffy G
you could do without a function, just use Math.max(value, 2.80) wherever you need the value like meouw suggested.
Anurag
where would i put Math.max(value,2.80)?
Tuffy G
in your panel.innerHTML, like `panel.innerHTML = Math.max(a, '2.80') + "something else"`
Anurag