Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a Simple Dynamic Site with Node.js Creating a Basic Template Engine in Node.js A Simple Merge Utility

Code Challenge Works in Dev Tools But Not in the Workspace

For the "A Simple Merge Utility" code challenge, I submitted the attached code. It said I needed to re-examine my implementation, though I saw nothing wrong with what I did. I called a coworker over to look at it and he saw nothing wrong with it either. He then suggested that I try my algorithm in the Dev Tools console in Chrome where it ran fine. I'm still not sure what the exercise submission tool wants from me, so any help in this capacity would be appreciated.

index.js
var utilities = require("./utilities");

var mailValues = {};

mailValues.first_name = "Janet";

var emailTemplate = "Hi %first_name%! Thanks for completing this code challenge :)";

var mergedContent = utilities.merge(emailTemplate, mailValues);

//mergedContent === "Hi Janet! Thanks for completing this code challenge :)";
utilities.js
function merge(content, values) {
  content = content.replace("%first_name%", values.first_name);
  console.log(content);
  return content;
}


module.exports.merge = merge;

1 Answer

Steven Parker
Steven Parker
229,644 Points

Be careful about testing challenge code externally. Code can "run fine" but still not meet the specific objectives of the challenge. And examples given will usually never be extensive enough to verify meeting the objectives by themselves.

While the example shown replaces "first_name", the challenge is looking for the function to be able to replace any property of the supplied object, no matter what the property name(s) may be.