Skip to content

Panthers Jan L.#74

Open
janliii wants to merge 7 commits intoAda-C18:mainfrom
janliii:main
Open

Panthers Jan L.#74
janliii wants to merge 7 commits intoAda-C18:mainfrom
janliii:main

Conversation

@janliii
Copy link
Copy Markdown

@janliii janliii commented Dec 12, 2022

No description provided.

Comment thread src/index.js
} else if (state.temp >= 80) {
tempColor.style.color = 'red';
newLS.src = `assets/hot1.jpeg`;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The logic here is correct, the only thing that is that you didn't need to put state.temp >= 50 && state.temp < 59 and then (state.temp >= 60 && state.temp < 69). You could just do state.temp > 50 and state.temp > 60. These take care of the range between these two numbers.

Comment thread src/index.js
.catch((error) => {
console.log('error!', 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.

You handled this nested promise chaining very well! However there is a way we can make this code more concise! Making use of the async & await functionality in Javascript:

const findLocation = async (query) => {
  try {
      const coordinates = await axios.get('http://127.0.0.1:5000/location', {
      params: {
        q: query,
        format: 'json',
      }})
  
      let latitude = coordinates.data[0].lat;
      let longitude = coordinates.data[0].lon;
     
      findWeather(latitude, longitude) 
    } catch (err) {
      console.log(err)
  }
} 

Essentially, the await keyword allows for us to stop the execution of the function we are in and wait for the promise it is attached to be fulfilled and resolved. Then we can save that returned data to a variable and go about our business! We will put this logic inside of try/catch blocks to handle errors. I also would suggest breaking the two functionalities (location and weather) into separate functions to avoid nesting.

Comment thread src/index.js

selectSky.addEventListener('change', (event) => {
const result = document.querySelector('.result');
result.textContent = `The sky is ${event.target.value}`;
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 love this use of the event object!

Comment thread src/index.js
realTimeButton.addEventListener('click', realTimeClick);
const reset = document.getElementById('resetButton');
reset.addEventListener('click', resetCity);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✨✨✨

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