Quote API Challenge Project (JavaScript)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines

How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.

Any idea about the solution’s post request - that if input is empty : should be 400 response but hit the submit button nothing happens ?


Solution code :

app.post(’/api/quotes’, (req, res) => {
const newQuote = {
quote: req.query.quote,
person: req.query.person
if (newQuote.quote && newQuote.person) {
res.send({ quote: newQuote });
} else {

Look in the browsers console

Challenge completed,

I had a bunch of (I’m sure remedial) questions and would truly appreciate answers. Apologies in advance for their obviousness, if that’s the case.

  1. why is the array quotes described as const { quotes } ? why wouldn’t it be just const quotes?

  2. why is the path /api.quotes/random? What does each piece of the path signify? I’m confused for two reasons. First, I can’t attribute the api in the path to anything. Secondly, I would have thought the path would end at quotes, as we’re just looking to take the quotes array from the data.js file. Obviously I don’t understand paths.

  3. I was used to including next in the arguments for the function along with res and req. This seemed to work but wasn’t in the solution. When does one use next?

  4. I just don’t understand the syntax of
    quote: getRandomElement(quotes)

That is, I don’t understand the curly brackets and the quote: array. I would have thought it would have been ok to just do res.send(getRandomElement(quotes));

  1. In this code: const newQuote = { quote: req.query.quote, person: req.query.person}
    How do I know to use req.query instead of req.params?
  1. Lastly, why does the path not have a colon?

Again sorry if these questions are super dumb. And thanks in advance.

Challenge completed. Now I will add the remaining HTTP verbs to have a complete CRUD Server. :smile: