HELP: Content creator project - No solution provided?

Hi, for the content creator project, I just can’t understand the solution provided.

link to the project: https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-conditionals-and-functions/modules/developing-javascript-apps-locally/informationals/bapi-p0-content-creators

link to the solution: https://www.codecademy.com/paths/create-a-back-end-app-with-javascript/tracks/bapi-javascript-conditionals-and-functions/modules/developing-javascript-apps-locally/informationals/content-creators-contracting-solution

I don’t see any change in the code provided… I should be missing on something I guess.

Can someone help me with that one as it has been 2 days that I have been trying to understand…

Thank you in advance!

Hi, I hope someone got around to answering this for you, but if you need a detailed explanation please don’t hesitate to message.

I’ll briefly try and explain the solution- i hope it helps.

So the task is asking for us to use the function that’s already been set up in the request-logic file:

the function is called getContentType which takes in a parameter called filename. The regex expression they’ve already provided is something we don’t have to really know the ins and outs about- regex is a topic in its own right and can be a little confusing if you’ve never come across it before.

the point is- the line const extension = filename.match(/.*\.([^\.]*)$/)[1] is a variable that spits out the extension for any filenames passed into the function.

We need to use this variable to write some conditional logic. The task is asking us to compare the extensions that are matched and return a specific file type.

What helped me was to first run npm test to see what the tests were failing.

if (extension === 'html') { //if the extension matches 'html', return 'text/html' and so on with the rest
    return 'text/html'
  } else if (extension === 'css') {
    return 'text/css'
  } else if (extension === 'jpeg' || extension === 'jpg') { //or operator being used for the same file type
    return 'image/jpeg'
  } else return 'text/plain' //any other extensions, 'text/plain' needed to be returned

I hope my explanation helped some. JS can be confusing, but you just have to keep chipping away and using muscle memory until it sticks- dont let it deter you! Keep it up! :slight_smile: