1
toggleClass()は$( 'p')で動作しないので、華氏と摂氏と華氏に戻って、何度もユーザーが望むように?コードへ
リンク:
//Our ID key for weather app
var appID = "&APPID=f74316dbe7442f12d602b1cae1a5172b";
var city;
var state;
var fahrenheit = "&units=imperial";
var temp;
//using a geo-location API to get city and state info of current user
$.getJSON('http://ip-api.com/json/?callback=?', function(data) {
city = data.city;
state = data.regionName;
getWeather(city, state);
});
//using weather API and outputting results into our HTML
function getWeather(city, state) {
var api = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "," + state + "" + fahrenheit + "" + appID;
$.ajax({
url: api,
dataType: 'json',
success: function(data) {
temp = data.main.temp;
$('h3').text(city + "," + state);
$('p').html(temp + '° F');
}
});
}
$('p').on('click', function(){
$('p').text(changeTemp(temp));
$('p').toggleClass(changeTemp(temp));
});
function changeTemp(temp){
var cel = (temp - 32) * 5/9;
return cel;
};
はFreeCodeCamp、いい仕事から天気アプリの挑戦のように見えます! –