rn_8 Posted November 13, 2012 Posted November 13, 2012 I have created an html file that utilizes a library. The library stores the calculation function of dew point and wind chill. The goal of this file is to input temperature, humidity and wind and to produce the outputs of either dew point or wind chill. I am having trouble getting the output to come up at all. The following is the code for my library, saved as weather.js: function CalculateDewPoint(dew) // Assumes: the temperature is measured in degrees Fahrenheit, humidity is measured in relative humidity // Returns: the corresponding due point will be calculated in degrees Fahrenheit { var dew; dew = temp - ((100 - humid) / 2.778); return dew; } function CalculateWindChill(wc) // Assumes: the temperature is measured in degrees Fahrenheit, the wind is measured in miles per hour // Returns: the corresponding wind chill will be calculated in degrees Fahrenheit { var wc; wc = 35.74 + 0.6215 * temp + (0.4275 * temp - 35.75) * Math.pow (wind , 0.16); return wc; } And the html file, indexes.html, is as follows: <!doctype html> <html> <head> <title>Weather Index</title> <script type="text/javascript" src="weather.js"></script> <script type="text/javascript"> function CalculateDewPoint() // Assumes: tempBox contains a temperature in degrees Fahrenheit, humidBox contains a relative humidity // Results: display the dew point in degrees Fahrenheit in outputDiv { var dew, temp, humid; temp = parseFloat(document.getElementById('tempBox').value); humid = parseFloat(document.getElementById('humidBox').value); dew = CalculateDewPoint(dew); document.getElementById('outputDiv').innerHTML = 'The temperature at which water vapor will condense into dew is at ' + dew + ' degrees Fahrenheit.'; } function CalculateWindChill() // Assumes: tempBox contains a temperature in degrees Fahrenheit, windBox contains a wind speed in miles per hour // Results: display the wind chill in degrees Fahrenheit in outputDiv { var wc, temp, wind; temp = parseFloat(document.getElementById('tempBox').value); wind = parseFloat(document.getElementById('humidBox').value); wc = CalculateWindChill(wc); document.getElementById('outputDiv').innerHTML = 'The wind chill factor is ' + wc + ' degrees Fahrenheit.'; } </script> </head> <body> <h2>Weather Index</h2> <p>Temperature (F): <input type="text" id="tempBox" size=6 value=1> Humidity(%): <input type="text" id="humidBox" size=6 value=1> Wind (mph): <input type="text" id="windBox" size=6 value=1> <input type="button" value="Calculate Dew Point" onclick="CalculateDewPoint();"> <input type="button" value="Calculate Wind Chill" onclick="CalculateWindChill();"> </p> <hr> <div id="outputDiv"></div> </body> </html> Please let me know if you can find any errors in this code that would allow this to function properly.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now