# Why Are My Class Variables Not Working? \[SOLVED\]

**URL:** <https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401>\
**Category:** Beginners\
**Created:** [October 23, 2022, 7:25pm UTC](https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401 "2022-10-23T19:25:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcgreen24](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bcgreen24/32/17248_2.png) [@bcgreen24](https://discourse.processing.org/u/bcgreen24)\
**Post date:** [October 23, 2022, 7:25pm UTC](https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401/1 "2022-10-23T19:25:30Z")

</div>

I was having issues with a sketch I was working on, so I created this little test to try and narrow down the issue-- which is that `this.x` and `this.y` are both undefined, even though the `Walker` class has a constructor which sets them both to an initial value. Help, what’s going on here?

```auto
class Walker{
  contructor(){
    this.x = 400;
    this.y = 400;
  }

  display(){
   console.log(this.x + ", " + this.y);
  }
}

let w = new Walker();
w.display(); // prints `undefined, undefined`

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 23, 2022, 7:41pm UTC](https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401/2 "2022-10-23T19:41:27Z")

</div>

Bring the last 2 lines in a function setup() :

```auto
void setup() {
    let w = new Walker();
    w.display(); 
}

```

---

<div class="post-metadata">

**Author:** ![bcgreen24](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bcgreen24/32/17248_2.png) [@bcgreen24](https://discourse.processing.org/u/bcgreen24)\
**Post date:** [October 23, 2022, 8:09pm UTC](https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401/3 "2022-10-23T20:09:20Z")

</div>

I should be able to create a new object outside of the setup function. In any case, I did that and I’m seeing the same behavior, as expected.

---

<div class="post-metadata">

**Author:** ![bcgreen24](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bcgreen24/32/17248_2.png) [@bcgreen24](https://discourse.processing.org/u/bcgreen24)\
**Post date:** [October 23, 2022, 8:13pm UTC](https://discourse.processing.org/t/why-are-my-class-variables-not-working-solved/39401/4 "2022-10-23T20:13:14Z")

</div>

LOL omg…it was a typo: `contructor` should be `constructor`.

OOPS…
