mercredi 12 août 2020

Generating a random number that is even by 10 in js

I'm making a snake game and have hit a stop when generating the food coordinates. I want a random number that is even by 10. By that i mean that it has to be a number mod(10) == 0. The snake is of width 10 so in order to have the coordinates match i need numbers like 80,130,10,40,200 Only even numbers without singulars are allowed. This is my current.

let width = 100;
let height = 100;
       
let x = Math.floor(Math.random()*width/2)*2;
let y = Math.floor(Math.random()*height/2)*2;

console.log(x + " : " + y);



Aucun commentaire:

Enregistrer un commentaire