Random Meat Quotes

Random Meat Quotes
0

#1

Here’s my random quote app: Meat quotes from random folks

Feedback welcome!

Cheers,
Tom


#2

@nicedrop - I like it because it unique! I noticed you have two separate event listeners for the button click. Why not just one that calls both APIs? See below for how that could have been accomplished. Also, I made a standalone errorMsg function to display any errors for the catch method. See how I used bind to pass a value to the standalone function.

reqQuote.addEventListener("click", function() {
  axios
    .get(urlQuote)
    .then(function(response) {
      meatQuote = `"${response.data[0]}"`;
      showQuoteText.innerText = meatQuote;
    })
    .catch(errorMsg.bind(null, 'quote'));
    axios
    .get(urlName)
    .then(function(response) {
      fullNameBy = `~ ${response.data["name"]} ${response.data["surname"]}`;
      showNameText.innerText = fullNameBy;
    })
    .catch(errorMsg.bind(null, 'name'));
});

function errorMsg(item) {
  console.log(`Error, no ${item}!`);
}

#3

Thank you, Randell! That’s neat. I had to review bind on MDN to see what your were doing with null: creating a preset leading argument. Nice!

Cheers,
Tom