Build a Project Idea Board - Build a Project Idea Board

Tell us what’s happening:

I’m currently working on a Lab about classes. It’s been some time since I’ve worked with classes and I am confused on how I can access the current object’s properties from another class. I need to return a string that prints out the ‘ProjectIdea title’ as well as ‘ProjectIdea status description’. I am unsure if I should be extending the ‘ProjectIdea’ class to inherit it’s properties then use them in the ‘ProjectIdeaBoard’ class or if I should be doing something differently.

Your code so far

const projectStatus = {
  PENDING: {description: "Pending Execution"},
  SUCCESS: {description: "Executed Successfully"},
  FAILURE: {description: "Execution Failed"}
};

class ProjectIdea {
  status = projectStatus.PENDING;

  constructor(title, description) {
    this.title = title;
    this.description = description;
  }

  updateProjectStatus(newStatus) {
    this.status = newStatus;
  }
}

class ProjectIdeaBoard {
  constructor(title) {
    this.title = title;

    const ideas = [];
  }

  pin(projectIdeaClass) {
    ideas.push(projectIdeaClass);
  }

  unpin(projectIdeaClass) {
    ideas.pop(projectIdeaClass);
  }

  count() {
    return ideas.length;
  }

  // How can I access the ProjectIdea title if its in a different class?
  formatToString() {
    return `
            ${this.title} has ${count()} idea(s)
            <ProjectIdea title> (<ProjectIdea status description>) - <ProjectIdea description>
            <ProjectIdea title> (<ProjectIdea status description>) - <ProjectIdea description>
            .
            .
            .`
  }
}

Current step I’m stuck on:

  1. You should define a method named formatToString that returns the name of the projects ideas, their description and status in the format:
<ProjectIdeaBoard title> has <ProjectIdeaBoard count> idea(s)
<ProjectIdea title> (<ProjectIdea status description>) - <ProjectIdea description>
<ProjectIdea title> (<ProjectIdea status description>) - <ProjectIdea description>
.
.
.

Challenge Information:

Build a Project Idea Board - Build a Project Idea Board

Hi @xSaberNight

6. Your ProjectIdeaBoard should initialize the title property based on the parameter passed and initialize an empty array named ideas to hold instances of the ProjectIdea class.

Try intialising the ideas array another way.

Happy coding

1 Like

Hm, I assume I should still be initializing it within the constructor? I omitted the ‘.this’ keyword for this change, but it doesn’t pass the given test case.

const projectStatus = {

  PENDING: {description: "Pending Execution"},

  SUCCESS: {description: "Executed Successfully"},

  FAILURE: {description: "Execution Failed"}

};




class ProjectIdea {

  status = projectStatus.PENDING;




  constructor(title, description) {

    this.title = title;

    this.description = description;

  }




  updateProjectStatus(newStatus) {

    this.status = newStatus;

  }

}




class ProjectIdeaBoard {

  // Field declaration don't use keywords like 'let' or 'const'

  // ideas = [];




  constructor(title) {

    this.title = title;
    ideas = [];

    // this.projectIdea = new ProjectIdea();

  }




  pin(ProjectIdea) {

    ideas.push(ProjectIdea);

  }




  unpin(ProjectIdea) {

    ideas.pop(ProjectIdea);

  }




  count() {

    return ideas.length;

  }




  formatToString() {

    string = `${this.title} has ${count()} idea(s)\n`;




    for (const element of this.ideas) {

      string += `${this.ideas[element].title} (${this.ideas[element].status}) - ${this.ideas[element].description}\n`

    }




    return string;

  }

}

I’ve made the following changes to the formatToString() instance method due to some help on a stack overflow forum post.

Try using the this keyword.

1 Like

Ah, okay I added the ‘this’ keyword back and thanks to some help from some people on stack overflow I was able to make the following revisions to the program:

const projectStatus = {

  PENDING: {description: "Pending Execution"},

  SUCCESS: {description: "Executed Successfully"},

  FAILURE: {description: "Execution Failed"}

};




class ProjectIdea {

  status = projectStatus.PENDING;




  constructor(title, description) {

    this.title = title;

    this.description = description;

  }




  updateProjectStatus(newStatus) {

    this.status = newStatus;

  }

}




class ProjectIdeaBoard {

  constructor(title) {

    this.title = title;

    this.ideas = [];

  }




  pin(idea) {

    this.ideas.push(idea);

  }




  unpin(idea) {

    this.ideas = this.ideas.filter(i => i !== idea);

  }




  count() {

    return this.ideas.length;

  }




  formatToString() {

    return `${this.title} has ${this.count()} idea(s)

            ${this.ideas.map(i => `${i.title} (${i.status.description}) - ${i.description}`).join('\n')}

           `;

  }

}

However, I still appear to be failing 2 test cases:

17. When new ProjectIdeaBoard("Empty Board") is empty, emptyBoard.formatToString() should return Empty Board has 0 idea(s)\n.


18. When you pin new ProjectIdea("Smart Home System", "An integrated system to control lighting, temperature, and security devices remotely.") to new ProjectIdeaBoard("Tech Projects Board"), techProjects.formatToString() should return Tech Projects Board has 1 idea(s)\nSmart Home System (Pending Execution) - An integrated system to control lighting, temperature, and security devices remotely.\n.

I’m curious where else the syntax may be causing these issues or if I am accessing the properties/values incorrectly.

Make sure to remove any extra whitespace and new lines.

Happy coding

1 Like

Ah, I see. I was able to finally fix it thank you!

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.