# Cant figure this out/help with code ASAP

**URL:** <https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686>\
**Category:** Coding Questions\
**Created:** [April 27, 2021, 7:12pm UTC](https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686 "2021-04-27T19:12:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Astromdahl01](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Astromdahl01](https://discourse.processing.org/u/Astromdahl01)\
**Post date:** [April 27, 2021, 7:12pm UTC](https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686/1 "2021-04-27T19:12:09Z")

</div>

Hello, I need Help with some code, I want The record to move around freely on the canvas and go to a random x and y and repeat constantly. is there a way I can do this? here is the link to y project

[https://editor.p5js.org/astromdahl01/sketches/81BgndIS5](https://editor.p5js.org/astromdahl01/sketches/81BgndIS5)

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [April 27, 2021, 7:23pm UTC](https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686/2 "2021-04-27T19:23:24Z")

</div>

Hi @Astromdahl01 ,

Welcome to the forum! 😉

The p5js reference is very good, you should take a look at it :

[https://p5js.org/reference/](https://p5js.org/reference/)

You talked about randomness so this is for you :

- [random()](https://p5js.org/reference/#/p5/random)

Then it’s just a matter of using random values to display your circles randomly and use the `draw()` function to constantly change that!

---

<div class="post-metadata">

**Author:** ![Astromdahl01](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Astromdahl01](https://discourse.processing.org/u/Astromdahl01)\
**Post date:** [April 27, 2021, 7:33pm UTC](https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686/3 "2021-04-27T19:33:13Z")

</div>

Hi @josephh I’ve looked at Radnomd() and it was somewhat helpful. when I try and enter random on line 27 or create a line that says: x = random(width) and both times it made multiple records, I just want one record that jumps around and random locations. Thanks for the response!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [April 27, 2021, 8:53pm UTC](https://discourse.processing.org/t/cant-figure-this-out-help-with-code-asap/29686/4 "2021-04-27T20:53:12Z")

</div>

Ok so you want one record that moves at random locations each time but in your code you are creating them inside a for loop (with the number of records) :

```auto
for(var b=0;b<numrows;b++) {
  let newRecord = new vinyl(x, y);
  records.push(newRecord);
}

```

So you still want to keep that?

Also the way you are defining your “vinyl” class is not really the right way to do it in JavaScript.  
If you want to keep that functional style, you should use [Object prototypes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) for that :

```auto
// Constructor
function Vinyl(x, y) {
  this.x = x;
  this.y = y;
}

Vinyl.prototype.display = function() {
  // Display
}

// Create a new vinyl
const vinyl = new Vinyl(500, 200);
vinyl.display();

```

Now since ES5, you can use more standard OOP syntax to declare a class (see the [MDN doc](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Classes) about that, it’s roughly equivalent, it’s a syntactic sugar) :

```auto
class Vinyl {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }

  display() {
    // ...
  }
}

```

Also note that most often in programming, classes names have the first letter uppercase ([PascalCase](https://en.wikipedia.org/w/index.php?title=Pascal_case)).
