cloudy cloudy

Author Topic: C to F function for AJAX pages  (Read 2195 times)

0 Members and 1 Guest are viewing this topic.

Offline TechScribe

  • Posts: 45
  • Davis Weather Vue
  • Kirkland, Washington USA
    • KirklandWeather.com
C to F function for AJAX pages
« on: November 19, 2006, 10:05:17 PM »
Another function suggestion to those of you using the AJAX Carter Lake template on how to clean up your scripts.

Instead of doing the math here:

temp = (1.8 * x.responseText.split(' ')[4]) + 32.0;

create a function and add it to the top of the AJAX script section

function convertCtoF(celcius)
// Take temperature value in Metric (Celcius)
// and convert to Fahrenheit
{
   return (1.8 * celcius) + 32.0;
}


then whenever you need to convert, just use the function.  For example:

temp = convertCtoF(x.responseText.split(' ')[4]);

Since you have to use this conversion several times on your page for temps and trends, it's a cleaner approach.