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 trialAndrew Gursky
12,576 PointsCode challenge at the end stage 3 not working
For some reason I can't get the code to work. The answer (in my mind) should be a simple replace, and when I test the code on my own, it works the way it should, but treehouse won't accept the answer. I know this is simple. What am I doing wrong?
1 Answer
Rafael Capati
10,725 PointsHi Andrew, can you post your solution? Maybe it's a Treehouse temporary problem with the challenges or a little detail in the code that the challenge is not accepting.
This is how I did:
function merge(content, values) {
for (var key in values) {
content = content.replace("%" + key + "%", values[key]);
}
return content;
}
module.exports.merge = merge;
Andrew Gursky
12,576 PointsAndrew Gursky
12,576 PointsHi Rafael,
Originally I did: content = content.replace('%first_name%', values.first_name); and treehouse wouldn't take it. Then I found something similar to what you did and copied and pasted it into the challenge just to see if it would work, and it did. What you have is the correct answer.
I was about to write that I didn't understand why it worked, but I just got it.
Thanks:)