Help with JavaScript Homework (for loops and arrays)

I need to answer these questions about the code below, and am having trouble understanding them…

I also need to make the circles into squares with the same width and height, but I’m not sure where I can control the w and h.

Here’s what I’m working with:

function setup() {
  createCanvas(400, 400);
}

var x = []; // new empty array
var y = []; // new empty array

function draw() {
  background(255);
  noFill();

  x.push(mouseX); // equivalent to append(x, mouseX)
  y.push(mouseY); // equivalent to append(y, mouseY)

  for (var i = 0; i < x.length; i = i + 11) {
    square(x[i], y[i], 1 + (x.length - i));
  }

  x = x.slice(-50); // keep the last 50 x values
  y = y.slice(-50); // keep the last 50 y values
}
1 Like

Did you look at the Canvas API?

I’m not sure, but it looks like you might be using either a library or helper functions, what is square() it looks like a helper function. If you are using a library look at the documentation for it.

Anyway, you likely need to replace square with a circle function and provide the dimensions much like it is done for the square function.