Why does my Log say the Value is NaN?

well, i have this part of my code inside the js now everytime the loop runs it's supposed to generate a random value for x , y , vX , vY and r but when I log the value inside the loop it says all those variables r NaN this is the part
for(let i=0; i<100; i++){

x = Math.random * innerWidth;
y = Math.random * innerHeight;
vX = Math.random * 10 - 5;
vY = Math.random * 20 - 10;
r = Math.random * 30;
console.log(x);

circleArray.push(new Circle(x,y,vX,vY,r));

}
for(let i=0; i<100; i++){

x = Math.random * innerWidth;
y = Math.random * innerHeight;
vX = Math.random * 10 - 5;
vY = Math.random * 20 - 10;
r = Math.random * 30;
console.log(x);

circleArray.push(new Circle(x,y,vX,vY,r));

}
and this is the codepen https://codepen.io/-bloop-/pen/bGxRpmw tnx!!
14 Replies
Jochem
Jochem•2y ago
That part isn't in the linked codepen, but Math.random isn't a value, it's a function
glutonium
glutoniumOP•2y ago
i deleted the previous code and inputted it i think i need to save it I don't use codepen so Idk can u try it rn? i saved the new code
Jochem
Jochem•2y ago
you can also just make a new one, you can make quite a lot
glutonium
glutoniumOP•2y ago
ahahah..okee
Jochem
Jochem•2y ago
yup, this works:
x = Math.random() * innerWidth;

y = Math.random() * innerHeight;

vX = Math.random() * 10 - 5;

vY = Math.random() * 20 - 10;

r = Math.random() * 30;
x = Math.random() * innerWidth;

y = Math.random() * innerHeight;

vX = Math.random() * 10 - 5;

vY = Math.random() * 20 - 10;

r = Math.random() * 30;
glutonium
glutoniumOP•2y ago
ooh wait lmaao
Jochem
Jochem•2y ago
you have to call random, it's not just a value you can use
glutonium
glutoniumOP•2y ago
I didn't add the parentheses ;-; sorry
Jochem
Jochem•2y ago
no worries, stuff like this happens to everyone, no matter how long you've been programming 😄
glutonium
glutoniumOP•2y ago
works..ty xD
glutonium
glutoniumOP•2y ago
@jochemm how is it xD
glutonium
glutoniumOP•2y ago
canvas is kinda fun
Jochem
Jochem•2y ago
looks good! I've never really played with canvas, I know you can do some wild things with it
glutonium
glutoniumOP•2y ago
ahaha yee
Want results from more Discord servers?
Add your server