Tests 8 & 9 Don't like my functions | Build a Random Quote Machine

Tests 8 & 9 Don't like my functions | Build a Random Quote Machine
0

#1

Tell us what’s happening:
Everything works swimmingly, but tests 8 & 9 are throwing errors:

Blockquote
8. When the #new-quote button is clicked, my quote machine should fetch a new quote and display it in the #text element. Uncaught ReferenceError: qetNewQuote is not defined (pen.js:217)
Error: Uncaught ReferenceError: qetNewQuote is not defined (pen.js:217)
at uncaughtException.i.onerror (https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.min.js:1:865)
9. My quote machine should fetch the new quote’s author when the #new-quote button is clicked and display it in the #author element. Uncaught ReferenceError: qetNewQuote is not defined (pen.js:217)
Error: Uncaught ReferenceError: qetNewQuote is not defined (pen.js:217)
at uncaughtException.i.onerror (https://cdnjs.cloudflare.com/ajax/libs/mocha/5.2.0/mocha.min.js:1:865)

Your code so far

JS:

var render = function (template, node) {
    node.innerHTML = template;
};

function getFirstQuote(){
  getNewQuote();
};

// function reqListener() {
//   qetNewQuote();
// };

function updateProgress (oEvent) {
  if (oEvent.lengthComputable) {
    var percentComplete = oEvent.loaded / oEvent.total * 100;
    // console.log(`%: ${percentComplete}`);
    var text = `<h1>${percentComplete}</h1>`;
     render(text, document.querySelector('#text'));
  } else {
    console.log('Danger, Will Robinson!');
  }
}
function parseQuote(response){
  let quote = {
    quoteText: (JSON.parse(response)[0].quote),
     author: (JSON.parse(response)[0].character)
  };
  return quote;
};
function renderQuote(quote){
     if(quote){
        var text = `<h1>${quote.quoteText}</h1>`;
        render(text, document.querySelector('#text'));
        var author = `<p>~ ${quote.author}</p>`;
        render(author, document.querySelector('#author'));
      } else {
        render('Error', document.querySelector('#text'));
      };
  renderSocial(quote);
};

function renderSocial(quote){
     var tweet = '<a id="#tweet-quote" href=https://twitter.com/intent/tweet?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + quote.quoteText + '" ' + '~ '+quote.author) + ' target="_blank"><i class="fab fa-twitter-square fa-2x"></i> </>'
  render(tweet, document.querySelector('#tweet-quote'));
  var facebook= '<a href=http://www.facebook.com/share.php?hashtags=quotes&related=freecodecamp&text=' + encodeURIComponent('"' + quote.quoteText + '" ' + '~ '+quote.author) + ' target="_blank"><i class="fab fa-facebook-square fa-2x"></i></>'
  render(facebook, document.querySelector('#facebook'));
};

function renderError(status,error){
  render(`Status: ${status} Error: ${error}`, document.querySelector('#text'));
};


let xhr = new XMLHttpRequest();

// xhr.addEventListener("load", reqListener);
xhr.addEventListener("progress",updateProgress);

function getNewQuote(){
  const url = `https://thesimpsonsquoteapi.glitch.me/quotes`;
    xhr.open("GET", url, true);
    xhr.responseType = "JSON";
    xhr.onreadystatechange = function () {
    if(xhr.readyState === 4 && xhr.status === 200) {
      let parsedQuote = parseQuote(xhr.responseText);
      renderQuote(parsedQuote);
      } else {
    // console.log(`status: ${xhr.status}`);
       renderError(xhr.status, xhr.statusText);
      }
    };
  xhr.send();
};

$('#new-quote').on('click', getNewQuote);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-random-quote-machine


#2

#RESOLVED
AAAARGGGH!!!

Nothing in the user stories state that the function called to load quote must be named getQuote.

Once I changed the fn name from getNewQuote to getQuote, all tests passed.

Thanks for reading.

Best,
Michael


#3

The name of the function can be “SantaClaus” if you want and the tests will pass. You just have to make sure you call the function with the same name throughout your code. I forked your pen and changed the function name to something different and it passes all the tests.


#4

Thanks… Apparently, I must have had a type in the function name… somewhere.

I guess that’s an argument for developing in an editor with spell-checking, or at least, with consistency checking!

/jmt