How to make a random position boxes

Help please. I don’t know how to make random position as if i add var or let, it doesn’t run the code. Here is the code i am working on.

function colorBox(color, x, y) {
  svg.append('rect').attr('width', 40).attr('height', 40).attr('x', x).attr('y', y).attr('fill', color)
colorBox('blue', 0, 30)

I Am Just About To Add pickRandom() To it Like This.

function colorBox(color, x, y) {
  var x = pickRandom([
    0,
    40,
    80,
  ]);
  svg.append('rect').attr('width', 40).attr('height', 40).attr('x', x).attr('y', y).attr('fill', color)
colorBox('blue', 0, 30)

But An Error Says That x has Duplicate Declaration. If I Remove var And Add x = 0 + 1 or x = x +1. It Didn’t Run. If I Put let it Will Be The Same as var.

Help, Help. I Don’t Know What i am Missing.

:disappointed_relieved: :disappointed_relieved: :disappointed_relieved:

Putting a variable in the parameters declares that variable. So when you have colorBox(color,x,y), you have declared the color variable, the x variable, and the y variable. So;when you say var x you are declaring x a second time.

try setting x to the array when you call colorBox, such as colorBox("blue", [0,40,80], 30)then setting a new var in the colorBox function called randX like var randX = pickRandom(x); and then setting the last line to svg.append('rect').attr('width', 40).attr('height', 40).attr('x', randX).attr('y', y).attr('fill', color) colorBox('blue', 0, 30).