Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement in javascript

Status
Not open for further replies.

xperience2

Programmer
Jul 3, 2007
1
Apologies for the, what I'm sure is a very rooky question, but I don't do much in Javascript!

I need to conditionally display the word 'mile' or 'miles' depending on whether the variable is '1' or more than 1.

I currently have:

document.getElementById('distance').innerHTML = "You are " + stores[0].distance + " miles from your nearest store.";

Can someone write me an if ... then ... else statement to work with this?

Thanks!

Simon
 
something like the following should work :

var distance=stores[0].distance;
var mileType="miles";

if (parseInt(distance)==1)
{
mileType="mile";
}

document.getElementById('distance').innerHTML = "You are " + distance + " " + mileType + " from your nearest store.";

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top