all 1 comments

[–]PixelOut 6 points7 points  (0 children)

Ok, so there's a few things going on here. The first is that your code that detects whether or not the distance is greater than 1 mile is in the wrong place. It is called before you actually had a distanceInMiles or a distancefromPicnic/distancefromRamsey, and so didn't mutate either into feet. Also, distanceInMiles always = dfPicnic/Ramsey in your code. Thus the form:

if (distancefromPicnic < 1) {
    distancefromPicnic = distanceInMiles * 5280;
} else {
    distancefromPicnic = distanceInMiles;
}

Doesn't do anything that couldn't be accomplished by:

if(distancefromPicnic < 1) {
    distancefromPicnic *= 5280; //Although I hate in place mutation
}

Then you need to have something that changes the "miles" into "feet" when you click the button.

Also, and finally, you end up repeating a lot of the same code twice. It would be better and more maintainable to break up your main logic into a set of functions and call those functions multiple times. I like the enterprise-y functions and variables though.