Console logging in React.js

Hello! After lots of difficulty I solved the
React Ravenous Part 4 Project.

However, I was unable to console.log to find out more information because the app failed to compile no matter where I put my console.log() statement. After searching the forums and other websites, I figured I must be doing something wrong because no one else seems to be having the same problem as me.

I tried to format my console.log exactly as recommended in this forum post

instead of giving me a console.log, the program fails to compile and tells me that the variable i am trying to log the value of is ‘not defined’. my code and the console error are below. Any help on the craft of console.log in react would be very much appreciated!

const apiKey = '<my_apiKey>'

const Yelp = {
    search(term, location, sortBy) {
        return fetch(`https://cors-anywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?term=${term}&location=${location}&sort_by=${sortBy}`, {
            headers: {
                Authorization: `Bearer ${apiKey}`
      }
        }).then(response => {
            return response.json(); 
        }).then(jsonResponse => {
            if (jsonResponse.businesses) {
                console.log(businesses)
                return jsonResponse.businesses.map((business) =>  ({
                    id: business.id,
                    imageSrc: business.image_url,
                    name: business.name,
                    address: business.location.address1,
                    city: business.location.city,
                    state: business.location.state,
                    zipCode: business.location.zip_code,
                    category: business.categories[0].title,
                    rating: business.rating,
                    reviewCount: business.review_count
                }));
        }})
    },
}

export default Yelp;

Failed to compile.

./src/util/Yelp.js
Line 13:29: ‘businesses’ is not defined no-undef

looking at this line:

if (jsonResponse.businesses) {

i would say businesses is a property of jsonResponse object, not a variable. So how would should we log this property?

1 Like

That did it, thanks @stetim94 ! I changed it to console.log(jsonResponse.businesses) and it compiled.

1 Like