Long time answer-lurker knocking my head against a wall that I can't find any solution for.
I'm working on the weather-showing app for FreeCodeCamp, and have almost got all the functionality done. The one remaining issue lies in my showWeather function, shown below.
function showWeather(data){
console.log('Running showWeather');
console.log(data);
$('#image').attr('src', data.weather[0].icon);
$('.card-title').html(data.weather[0].description);
$('#temperature').html(data.main.temp);
$('#high').html(data.main.temp_max);
$('#low').html(data.main.temp_min);
$('#windspeed').html(data.wind.speed);
$('#humidity').html(data.main.humidity);
$('#location').html(data.name);
console.log('Starting temp tests');
if (data.mane.temp > 32){
console.log('First temp test');
$('#icon').html('<i class="fas fa-thermometer-full"></i>');
} else if (data.main.temp > 21){
console.log('Second temp test');
$('#icon').html('<i class="fas fa-thermometer-three-quarters"></i>');
} else if (data.main.temp > 10){
console.log('Third temp test');
$('#icon').html('<i class="fas fa-thermometer-half"></i>');
} else if (data.main.temp > 0){
console.log('Fourth temp test');
$('#icon').html('<i class="fas fa-thermometer-quarter"></i>');
} else {
console.log('Final temp test');
$('#icon').html('<i class="fas fa-thermometer-empty"></i>');
}
console.log('Past temp tests');
}
It accepts a data object with a bunch of weather stats as an argument, and correctly edits all the weather stats on the page. The issue is in the last if/else part, which is supposed to look at the temperature and choose an appropriate thermometer symbol.
The issue is that the function seems to just stop at the first if statement. None of the logs past 'Starting temp tests' show up. Even the 'Past temp tests' at the end (which isn't even inside the if/else) doesn't appear in the console. If I comment out the entire if/else part then the 'Past temp tests' appears in the console, making it seem to me as if the function just ends after the 'Starting temp tests' is sent to the console.
I've puzzled over this for hours, checking for every typo I can think of and commenting out different parts. Does anybody have any ideas?
I'm using CodePen, by the way. Here is my pen. I'd really appreciate if someone could sort me out so I can move on with my life.
Aucun commentaire:
Enregistrer un commentaire