I have called the .push
function, but nothing is being added to my array. Here is my code:
function setup() {
createCanvas(400, 400);
}
let digits = [];
function binaryConverter(num){
this.num = num;
for(let i = 0; this.num === 0; i++){
digits.push(this.num % 2);
this.num = floor(this.num/=2);
}
}
function draw() {
background(220);
binaryConverter(13);
print(digits);
}
I expected the program to output the digits, but it outputs empty arrays.