I am working on a javaScript project and I am supposed to create a 3x3 grid using 3 different arrays (each one of them should have its own random order) and the print the result by using a class method.Is there a way to randomize each arrays class instance ? See code below:
const my_arr = ['^', 'O', '░', '*'];
let field = []
for (let i = 0; i < my_arr.length; i++) {
const randomIndex1 = Math.floor(Math.random() * 3);
field.push(my_arr[Math.floor(Math.random() * 3)])
//
//field.push(my_arr[randomIndex])
}
//console.log(field)
class Field {
constructor(field) {
this.field = field.reverse();
}
print() {
console.log(this.field.join(''))
}
}
const myField1 = new Field([field])
const myField2 = new Field([field])
const myField3 = new Field([field])
console.log(`${myField1.print()}\n${myField2.print()}\n${myField3.print()}`)
Any help is greatly appreciated.