Computer Choice: Part 1


here is my code:

var userChoice = function (choice){

choice = prompt("Do you choose rock,paper or scissor?s");
return choice;

var computerChoice = function (compChoice){
compChoice = Math.random();
return compChoice;


the error message states:
Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!

someone please help.


Well using functions for the choices is generally a good idea and good for practice but the exercise doesn't require it here. Nevertheless I tried it myself and it is possible to pass this using functions as well, but you still need to full fill the required tasks. Meaning that in the end your values are in userChoice and computerChoice and that you console.log computerChoice. This bascially means that you need to find different names for your functions idk choiceForUser instead of userChoice and then call it like this:

var userChoice = choiceForUser();

It's also the reason for the error because the test function expects computerChoice to be a random number but in your case it's a [Function] so it assumes that you messed up something using Math.random and not capitalizing the "M" had been a common error. As said this is not the case in your code using functions is fine you just need to be careful with the names because those that are mentioned in the instructions are usually those that the test function inspects in further detail.
Also if you directly overwrite the value of the parameter choice it is not really necessary to have one in the first place so:

var  choiceForUser = function(){
    var choice = prompt("Do you choose rock,paper or scissor?s");
    return choice;

should be sufficient. Hope this helps.


Thank you for the help, but I managed to figure it out :smiley: