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 trialDaniel Frisch
14,713 PointsComplete the implementation of the merge method in utilities.js file. You should be able to pass in a string with placeh
I don't under stand what is missing.
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(mailValues, content) {
for(var key in mailValues) {
content = content.replace("%" + key + "%", mailValues[key]);
}
return content;
}
module.exports.merge = merge;
2 Answers
Seth Shober
30,240 PointsYou've mixed up your arguments. emailTemplate
is the string you want to pass as content
, and mailValues
is the object you want to pass as mailValues
.
I believe this is what you meant to do:
var mergedContent = utilities.merge(mailValues, emailTemplate);
Daniel Frisch
14,713 PointsI figured it out. Thank you for trying to help out :) there was no need to change the argument names.
Seth Shober
30,240 PointsRight on. What was the fix? When I ran your code I got an error because content was expecting a string and was passed an object. That's why I switched the order, which matched the function you had written, and it worked.
Daniel Frisch
14,713 PointsI believe I did need to reverse the arguments in the merge function, but not the mergeContent variable. Also I didn't have to rename the content variable to say emailTemplate.
Seth Shober
30,240 Pointscool. sounds like we both had different ways of thinking about the same thing.