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

JavaScript

Damian Szymanski
Damian Szymanski
11,843 Points

Having a problem with my code. (Object Oriented Programming)

Hello! Im having a bit of a bug with my code that I can't seem to figure out.
I will include snippets of the code I isolated the problem down too.

Searching to Change banner:

bannerSubmit.addEventListener("click", () => {
    const bannerSearchInfo = () => {
        var bannerSearch = document.querySelector('#usrName2').value;
        var bannerTxt = document.querySelector("#msg2").value;
        var found = false;
        for (var i = 0; i < users.length; i++) {
            bannerUser = users[i];
            if (bannerSearch.toLowerCase() === user.name) {
                found = true;
                bannerUser.bannerText(bannerTxt);
});    

Actual Objects the search is referring too with there setters and getters:

var users = [{
    name: "damian",
    joinYear: 2019,
    numVid: 39,
    text: "",
    get bannerText() {
      this.text = "Hello! My name is " + this.name + ". I joined in the year " + this.joinYear + " and I have " + this.numVid + " videos.";
      return this.text;
    },
    set bannerText(val) {
      this.text = " ' " + val + " ' ";
      return this.text;
  },
    name: "monika",
    joinYear: 2020,
    numVid: 44,
    text: "",
    get bannerText() {
      this.text = "Hello! My name is " + this.name + ". I joined in the year " + this.joinYear + " and I have " + this.numVid + " videos.";
      return this.text;
    },
    set bannerText(val) {
      this.text = "'" + val + "'";
  },
  {    

Here is a link to a Codepen with all my code if that would help: https://codepen.io/Melon_Max/pen/pXaoPB

Thank you so much! Damian.

Mark Wilkowske
Mark Wilkowske
Courses Plus Student 18,131 Points

The Sign Up button in the modal has an open start tag: >. When fixed you can see the bad path error.

1 Answer

Steven Parker
Steven Parker
231,275 Points

How do you test on the codepen? I didn't see any list of users to check the search with.

Please describe the steps you take to exhibit the issue, and explain what the symptom is.

Damian Szymanski
Damian Szymanski
11,843 Points

Ah sorry. You can exhibit the bug by clicking on the "change Banner" button, typing in a name (ex: Damian), then typing in a banner msg in the second field then pressing the blue button. After this search, a name in the main search bar (ex: Damian) and the new banner msg does not show up.

Damian Szymanski
Damian Szymanski
11,843 Points

Also, you can view the list of users at the bottom of the js file :)

Steven Parker
Steven Parker
231,275 Points

It looks like the click handier defines a function named "bannerSearchInfo", but never invokes it.

Also, even it was invoked, the function compares the search term to "user.name", but nothing named "user" has been defined. Did you mean "bannerUser" instead?

Damian Szymanski
Damian Szymanski
11,843 Points

Hello! Thank you so much for the help so far! I am still getting one error: Uncaught TypeError: bannerUser.bannerText is not a function at bannerSearchInfo