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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Duy Khanh](https://secure.gravatar.com/avatar/ae2b03f738d9f0c240e406b2d5a1b587?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Duy Khanh
Courses Plus Student 4,911 PointsI dont know what im going wrong in this code ?
here is my router.js and the result : "username has 90 badges " all test alway result 90 badgers
var Profile = require("./profile.js");
//2 handle the http route GET / and POST / i.e Home
let home = (request, response) => {
//if url === '/' && 'GET'
if (request.url === '/') {
response.writeHead(200, { 'Content-Type': 'text/plan' });
response.write("Header\n");
response.write("Search\n");
response.end("footer\n");
}
//show search
//if url ==='/' && 'POST'
//redirect to /:username
}
//3 handle http route GET /username i.e /chalker
let user = (request, response) => {
//if url ==='/...'
var username = request.url.replace("/", "");
if (username.length > 0) {
response.writeHead(200, { 'Content-Type': 'text/plan' });
response.write("Header\n");
//get json from treehouse
var studentProfile = new Profile("username");
//on "end"
studentProfile.on("end", (profileJSON) => {
//store the value which we need
let values = {
avatarUrl: profileJSON.gravatar_url,
username: profileJSON["profile_name"],
badges: profileJSON.badges.length,
javascriptPoint: profileJSON.points["JavaScript"]
};
//simple response
console.log(values.javascriptPoint);
response.write(values.username + " has "+ values.badges + " badges " + "\n");
response.end("footer\n");
});
studentProfile.on("error", (error) => {
response.end("footer\n");
});
//show profile
//on "error"
//show error
}
}
module.exports.home = home;
module.exports.user = user;
1 Answer
![Howard Goldstein](https://secure.gravatar.com/avatar/cb5f603e96513a1bb8ec910125a38abf?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Howard Goldstein
9,399 PointsIt looks like you are calling Profile with a static "username" rather than with the variable username... so replace...
var studentProfile = new Profile("username");
with
var studentProfile = new Profile(username);
Duy Khanh
Courses Plus Student 4,911 PointsDuy Khanh
Courses Plus Student 4,911 PointsOh i have fixed is. but thanks you im so stupid have a good day !