Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Help with jQuery Plugin Script

Hey guys,

This post has nothing to do with any of the code challenges, or videos on this site but I find the responses I am getting over at stackoverflow.com/ are too difficult to understand, and the Treehouse community just rocks!

The script in question is from SimpleWeather and what I am after is the wind speed to be in knots instead of miles per hour.

I will include the attach the script to this post as it is quite small.

simpleWeather.js

The script below is what is added in the my html.

$(document).ready(function(){
    $.simpleWeather({
        location: 'Mundoo Island, SA, Australia',
        woeid: '',
        unit: 'c',

        // weather pull successful
        success: function(weather) {
            html = '<p>'+weather.temp+'&deg'+weather.units.temp+
            '<span> | </span><strong>'+weather.wind.direction+'</strong>'+' '+weather.wind.speed+' '+weather.units.speed+'</p>';

            $("#weather").html(html);
        },

        // weather pull error
        error: function(error) {
            $("#weather").html('<p>'+error+'</p>');
        }
    });
});

Any advice on how this can be achieved will be greatly appreciated, maybe Andrew Chalkley

3 Answers

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,815 Points

EDITED: Realized this morning I was using php variable declarations. Changed syntax.

Stu:

In your success function, I would think that something along these lines would give you the wind speed in knots:

var windSpeedMPH = weather.wind.speed;
var windSpeedKnots = Math.round(windSpeedMPH * 6076 / 5280);

Then echo windSpeedKnots out to your html instead of weather.wind.speed and replace weather.units.speed with 'kn'

Does that help?

Thanks Shawn,

You are a life saver mate. I have been scratching my head over this a bit too long!

Cheers

Stu :)