"GetComputerChoice" part


I’m stuck at this part for so long now, it keeps printing ‘Undefined’ everytime I run it.
My code is:

const getComputerChoice = () => {
let randomNumber = Math.random(Math.floor() * 3);
switch (randomNumber) {
case 0:
return “rock”;
case 1:
return “scissors”;
case 2:
return “paper”;

Can you please let me know why it doesn’t print rock, paper or scissors? Since it’s really annoying for me to be stuck and unable to identify what’s wrong, thank you in advance.


lets look at the value of randomNumber:

let randomNumber = Math.random(Math.floor() * 3);

seems something goes wrong when attempting to generate a random number, which is why not of the cases are true, and why you get undefined


Could you please tell me how to fix it ? I finished the whole task and this part is still not working properly no matter how I try to modify it…


the random number you generate:

Math.random(Math.floor() * 3);

isn’t correct, so you need to fix that. How did you try to modify it? You can always check documentation on MDN if you struggle with the math functions


Well, I’ve just figured it out! It was such a naive mistake by me :’)
I inserted Math.floor inside of Math.random while i just had to swap their places to fix it, just wow :'D


yes, very good. Figuring it out yourself is always better :slight_smile: Which is why i was trying to point you in that direction


Thank you so much! Now I can finally get some rest :'D


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.