停留在天气应用程序上进行免费代码挑战
stuck on weatherApp for freecode challenge
这次我卡在了 weatherApp 的 js 上。我正在逐步使用 yt 上的教程之一(根据我的想法),但代码的 backbone 没有我的想法。但是
function getWeather(loc) {
var lat = Math.floor(loc.split(",")[0]);
var lon = Math.floor(loc.split(",")[1]);
var weatherApiUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=5a1518c003259fdaa613a1aa78664ff9&";
console.log(weatherApiUrl);
$.get(weatherApiUrl, function(weather){
var temperature = weather.main.temp;
var description = weather.weather[0].description.toUpperCase();
var pressure = weather.main.preure;
console.log(weather);
我无法将天气变量记录到控制台,不知道为什么。
确保您正确包含了 jQuery 库,并查看以下内容:
function getWeather(loc) {
/* I'm not sure this is correct...
var lat = Math.floor(loc.split(",")[0]);
var lon = Math.floor(loc.split(",")[1]);
RATHER USE: */
// API will already float to .toFixed(2), so no need to do Math stuff...
var latLon = loc.split(","),
lat = latLon[0].trim(),
lon = latLon[1].trim();
var weatherApiUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=5a1518c003259fdaa613a1aa78664ff9";
$.get(weatherApiUrl, function(weather) {
var temperature = weather.main.temp;
var description = weather.weather[0].description.toUpperCase();
// var pressure = weather.main.preure; // preure? WTF?
console.log(weather);
});
}
getWeather("45.815399, 15.966568");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
这次我卡在了 weatherApp 的 js 上。我正在逐步使用 yt 上的教程之一(根据我的想法),但代码的 backbone 没有我的想法。但是
function getWeather(loc) {
var lat = Math.floor(loc.split(",")[0]);
var lon = Math.floor(loc.split(",")[1]);
var weatherApiUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=5a1518c003259fdaa613a1aa78664ff9&";
console.log(weatherApiUrl);
$.get(weatherApiUrl, function(weather){
var temperature = weather.main.temp;
var description = weather.weather[0].description.toUpperCase();
var pressure = weather.main.preure;
console.log(weather);
我无法将天气变量记录到控制台,不知道为什么。
确保您正确包含了 jQuery 库,并查看以下内容:
function getWeather(loc) {
/* I'm not sure this is correct...
var lat = Math.floor(loc.split(",")[0]);
var lon = Math.floor(loc.split(",")[1]);
RATHER USE: */
// API will already float to .toFixed(2), so no need to do Math stuff...
var latLon = loc.split(","),
lat = latLon[0].trim(),
lon = latLon[1].trim();
var weatherApiUrl = "http://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=5a1518c003259fdaa613a1aa78664ff9";
$.get(weatherApiUrl, function(weather) {
var temperature = weather.main.temp;
var description = weather.weather[0].description.toUpperCase();
// var pressure = weather.main.preure; // preure? WTF?
console.log(weather);
});
}
getWeather("45.815399, 15.966568");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>