Why is this the correct answer to the songFactory practice question?

I was going through a practice session today and encountered this question

What will be printed to the console by the included Javascript program?

const songFactory = (name, artist, album) => {
  return {
    _name: name,
    _artist: artist,
    _album: album,
    printInfo() {
      console.log(this._name + " by " + this._artist " from " + this._album); 

let song = songFactory("Thriller", "Michael Jackson", "Thriller");

…at this link, https://www.codecademy.com/practice/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/learn-javascript-objects/lessons/advanced-objects#4

This is the correct answer which I came to after guessing wrong a couple of times.

Can someone tell me why this is the correct answer? Because to me it seems like it should be this which is what I originally selected as the answer (and got wrong)

songFactory("Thriller", "Michael Jackson", "Thriller")

Hi there.

Let’s run the code, shall we?

Since we’re calling the songFactory() function, which returns an object we’ve subsequently assigned to the song variable, calling console.log(song) prints the object to the console.

I can’t get that particular question when I click through to the review material (I think it’s customised to each learner profile), but the answer being given as correct would seem to be a generalised version of what is printed…

I don’t know whether there’s an exact match on another answer or not, as I’m not being given the question (and your screenshot doesn’t show any other options :slight_smile: ).

1 Like

I’m unable to get the question to come up again myself – sorry I should’ve copied-and-pasted all the possible answers. My mistake. I will say the other two possibles were very obviously not correct which left the ones I did capture.

I can also tell you the answer with the green background highlight is the correct one according to Codecademy (that formatting is how they show you got the right answer on these practice quizzes). Plus I can say there was no answer listed that looked exactly like the one that evaluated when you ran the code.

Oddly, this is what evaluated when I ran the code in my console which is yet another reason I was having trouble with this question, besides the strange way the wrote out the “correct” answer.

1 Like

I think your console.log() call is missing a concatenation operator +. :slight_smile:

I copied and pasted this code directly from the quiz question, so I didn’t miss it, Codecademy did. But who’s counting right?

1 Like

I’ve just been through those practice questions on a loop to try and get that one… and you’re right, the question is wrong!

I’ll raise it with CC and see if we can get it fixed. :slight_smile:

Edit: I’ve logged a ticket with CC now, so this hopefully will get fixed. :slight_smile:

1 Like