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


I am having javascript Points as undefined on the result page

<ul> <li><span>110</span> Badges earned</li> <li><span>undefined</span> JavaScript points</li> <li><a href="/">search again</a></li> </ul>

i don't know maybe it's a mistake somewhere. Anyone that had the same problem pls let me know how u resolved it.

Steven Parker
Steven Parker
229,921 Points

You would need to show all the code for it to be possible to located the error. The best way is to make a snapshot of your workspace and post the link to it here.

It's on the full-stack javascript course. (Build a Simple Dynamic Site with Node.js) I've made it to the "binding values" part. Everything is working perfectly. but i'm getting undefined javascript points when i try to enter any username. here is the link to the result screenshots. https://res.cloudinary.com/benbasty/image/upload/v1529599128/Screen_Shot_2018-06-22_at_12.38.26_AM.png https://res.cloudinary.com/benbasty/image/upload/v1529599128/Screen_Shot_2018-06-22_at_12.38.26_AM.png

And here is the code. App.js

// create a web server 
var router = require('./router.js');
var http = require('http');
http.createServer(function(request, response){
  router.home(request, response);
  router.user(request, response);
  //response.end('Hello World\n');
  }). listen(3000);
console.log('Server running at http://<workspace-url>');


var Profile = require("./profile.js");
var renderer = require("./renderer.js");
var commonHeaders = {'Content-Type': 'text/html'};         
// handle a http route GET and POST 
function home(request, response){
     // if url ="/" && GET
  if(request.url === "/") {
      // show search
        response.writeHead(200, commonHeaders);
        renderer.view("header", {}, response);
        renderer.view("search", {}, response); 
        renderer.view("footer", {}, response);
      // if url == "/" && POST
        // redirect to :/username
// handle the http route for GET/: username i.e / chalkers
function user(request, response) {
      // if url == "/...."
  var username = request.url.replace("/", "");
  if(username.length > 0) {
    response.writeHead(200, commonHeaders);
    renderer.view("header", {}, response);
    var studentProfile = new Profile(username); 
    // on "end"
    studentProfile.on("end", function(profileJSON){
      // show profile
      // store the value needed
      var values = {
        avatarUrl: profileJSON.gravatar_url,
        username: profileJSON.profile_name,
        badges: profileJSON.badges.length,
        javascriptPoints : profileJSON.points.Javascript
      //Simple response
      renderer.view("profile", values, response);
      renderer.view("footer", {}, response);

    // on error
    studentProfile.on("error", function(error){
      // show error
      renderer.view("error", {errorMessage: error.message}, response); 
      renderer.view("search", {}, response);
      renderer.view("footer", {}, response);


var fs = require("fs");
function mergevalues(values, content) {
  for (var key in values) {
    content = content.replace("{{" + key + "}}", values[key]);
  return content;
//function that handles the reading of files and merge in values
        // read from file an get the strings
        // merge value from the string
function view(templateName, values, response) {
  // read from the template files
      var fileContents = fs.readFileSync('./views/' + templateName + '.html', {encoding: "utf8"});
  fileContents = mergevalues(values, fileContents);

module.exports.view = view;

2 Answers

Steven Parker
Steven Parker
229,921 Points

This code isn't complete. it's missing at least one more component named "profile.js".

And a snapshot is a complete clone of your workspace, it makes it easy to replicate the issue. It's not a "screenshot" (which is not very helpful).

okay i got it. here is the snapshot link http://w.trhou.se/w6pqzja3pa thanks))))

Steven Parker
Steven Parker
229,921 Points

On line 55 of "router.js" you have "profileJSON.points.Javascript" (with lower-case "s") instead of "profileJSON.points.JavaScript" (with capital "S").

Thank you so much. :) thanks alot.