---
# System prepended metadata

title: Untitled

---

**Tinker# 3 [Functions/ Objects/ Array]**
**Reflection:** 
I tinkered with the functions, objects and arrays on P5JS. I was able to explore how to organize variables under different function names as well as how to generate new objects by using initializers or construction. Arrays enable users to create repetitive commands for a certain code, allowing for multiple features to be called upon at once.

**Functions**: 
fundamental elements of JS, enabling for an efficient coding by categorizing operations under a single command. In P5 JS, we can use ellipse or backgrounds.

to declare functions in p5js, jot down the following: 
>     function setup () { // do something}

the name of the function should reflect what we want the program to do.

The term, "parameters" can be used interchangeably with "arguments". The parameters are the values that the users will eventually provide. However, when the function is provided by the user, it is known as "function arguments."  

* Functions are like "black boxes" containing variables that are not visible from outside the functions.

* Functions can operate without an input or with one, two inputs and produce a result or nothing at all.
* To be able to return a value from a fucntion, we need the variable, "return".

**Return**: this term stops the operation of the function that it's in and provides the value next to the function caller.

in P5JS, the functions, "setup" and "draw" are already established. 
Using functions allow us to contain our data in organized blocks.

**Dot Notation** users can add properties to the object using this feature.
**Sqaure Bracket Notation**: used to access properties on an object

**Properties vs. Methods**
    property: a value that belongs to an object
    methods: when function is a key value, the function is called a method.

'**this**': the term enables us to "refer to the properties defined on the object from within that object".

In JS, programming language has properties which describe how they are and methods that determine how they behave. 

**Objects**
**1. Object Initializers** used to create a single object.
**2. Constructor Function** 
...is a function constructed to be a blueprint for generating new objects. The first letter of their name should be capitalized for a convenient recall. If not capitalized, it will generate an unintended outcome.
For example: 
```

 `function Circle() {
     this.x = width/2;
     this.y = height/2;
     this.size = 50;
     this.draw = function () {
     ellipse(this.x, this.y, this.size, this.size);
     this.grow = function() {
     if (this.sie < 200) {
     this.size = this.size + 1;
     }
     }
     }
```

**Arrays**
"a sequential collection of data stored with a numbered index." An empty array is generated using square brackets.

```
var arr =[]
arr.push(1);
arr.push('hello world');
arr.push{{'name'; 'value'}}

var arr = [15, 33, 456, 33];
console.log(arr);
```
an array starts counting with a value "0". 
**Remainder operator (%)**


With two values, remainder operator returns the remainder from when the value on the first value on the left is divided by the second value on the right. 



```![](https://i.imgur.com/cBCRNdz.png)



var remainder = 10 % 3;
console.log(remainder);

