Reputation: 157
I am practicing my JavaScript and I am just trying to make a simple rock paper scissors game, I followed a little guide, but when I console.log it, it just prints the function not the array of choices. How do I get those choices?
let choice = ['Rock', 'Paper', 'Scissors'];
function computerPlay () {
return choice[Math.floor(Math.random * choice.length)];
}
console.log(computerPlay);
Upvotes: 0
Views: 105
Reputation: 10237
You need to make 2 changes for your code to run
Math.random()
console.log(computerPlay())
You need to call a function using fn_name() to execute it.
let choice = ['Rock', 'Paper', 'Scissors'];
function computerPlay() {
return choice[Math.floor(Math.random() * choice.length)];
}
console.log(computerPlay());
Upvotes: 2