Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Brian Peirce
Brian Peirce
14,702 Points

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.

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 :)";
function merge(content, values) {
  content = content.replace("%first_name%", values.first_name);
  return content;

module.exports.merge = merge;

1 Answer

Steven Parker
Steven Parker
217,573 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.