Skip to content

weather-report panthers Tiffany Rogers#90

Open
Tiffany-Rogers-Dev wants to merge 2 commits intoAda-C18:mainfrom
Tiffany-Rogers-Dev:main
Open

weather-report panthers Tiffany Rogers#90
Tiffany-Rogers-Dev wants to merge 2 commits intoAda-C18:mainfrom
Tiffany-Rogers-Dev:main

Conversation

@Tiffany-Rogers-Dev
Copy link
Copy Markdown

No description provided.

Comment thread src/index.js
.catch((error) => {
alert(error);
})
};
Copy link
Copy Markdown

@mikellewade mikellewade Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice promise chaining for these functions, Tiffany! I have one refactoring advice for you and that is to implement the async &c await functionality of Javascript in order to make your code more concise and readable. doing something like:

const getAPI = async () => {
  let lat, long;
  
try {
   const response = await axios.get('http://127.0.0.1:5000/location', {
      params: {
        q: userSearch.value,
        format: 'json',
      }})
  
    lat = response.data[0].lat;
    long = response.data[0].lon;
    
   getWeather(lat, long) 
} catch (err) {
    console.log(err);
  }
}

Using the await keyword lets us stop the global execution for the function it is in and wait for the promise to be fulfilled. This allows us to cut out the promise chaining here and just save return information from the axios calls as variables. We can then use said variables like we ordinarily would in the then chain of the promise. Then we can use a try/catch block for error handling. Finally, I would suggest breaking the location and weather API calls into their own functions so that you can avoid nesting try/blocks and just overall concise code.

Comment thread src/index.js
function increment(){
temp += 1;
temperature.textContent=temp
console.log(temp)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember to remove your console.logs before pushing into production!

Comment thread index.html
<label for="city-search">City Name</label>
<input type="text" id="city-search" value="Columbus" />
<button
style="
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When doing this much styling it is best to move it inside of your css file so it doesn't congest your html files.

Comment thread src/index.js
temperature.style.color="blue"
}else {
temperature.style.color="#1100ab"
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here you have the right idea for your if statements, however you could just put this here:

if (temp > 60) 

Comment thread src/index.js
spring.style.display="none"
fall.style.display="none"
winter.style.display="flex"
}
Copy link
Copy Markdown

@mikellewade mikellewade Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here, the refactor that I would suggest would start in the HTML file. Instead of putting all the landscapes I would just put one of them. Something like : <div id='landscape'></div> After that, I would change the code you have here into something like:

const landscape = document.getElementById('landscape')

if (temp >= 65) {
   landscape.innerHTML = 😎S☀️u🌞n🌅n🌞y😎
}

This way you can save your fingers from typing a lot more code! I would do the same thing in the dropDownValue function.

Comment thread src/index.js
defaultSky.style.display = 'none';
};

dropdownValue()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you are invoking the certain functions in order to get the intital data displayed on the first render of the page. I would just move these all somewhere together. Given that you used the function keyword your functions have been hoisted and you can move them anywhere you please.

Comment thread src/index.js
resetCityBtn.addEventListener('click', resetCity);
getWeatherBtn.addEventListener('click', getApi);
userSearch.addEventListener('input', displayInput);
skyDropDown.addEventListener('change', dropdownValue);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the only suggestion is to move these inside a registerHandlers function that is made the callback to theDOMContentLoadedevent handler.

Comment thread styles/index.css
}
footer{
text-align: center;
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, great work Tiffany! ✨

@Tiffany-Rogers-Dev
Copy link
Copy Markdown
Author

Tiffany-Rogers-Dev commented Jan 11, 2023 via email

@Tiffany-Rogers-Dev
Copy link
Copy Markdown
Author

Tiffany-Rogers-Dev commented Jan 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants