Issue with my project

Hi folks,

So I am building a rock, paper, scissors game but I keep getting an undefined in my function but I am lost.

Please could someone cast an eye over and let me know where I am going wrong:

Any guidance would be appreciated as my hair is now falling out…


function game(userChoice){
    const computerChoice = getComputerChoice();

    switch (userChoice + computerChoice) {
        case 'rs':
        case 'pr':
        case 'sp':
            win(userChoice, computerChoice);
        case 'rp':
        case 'ps':
        case 'sr':
            lose(userChoice, computerChoice);
        case 'rr':
        case 'pp':
        case 'ss':
            draw(userChoice, computerChoice);
1 Like

Thanks but I do not understand. :slight_smile:

I’ve look at your code and I’ve noticed that you call the function (let’s take win for example) like this:

win(userChoice + computerChoice); I don’t think you can pass the arguments like that you’d need to use a comma. You also do the same thing with your switch.

1 Like

Yeah I tried to use , but that didn’t do anything, let me update js fiddle now!

See nothing works now - odd right?!

Can you explain the logic of your switch statement for me?

1 Like

Thanks very much! I see where I was going mad… Case Closed!!! Thank you very much!!!

Switch take only one argument, so if the two variables have a value of one letter string than the switch statement was done correctly

1 Like

Thanks for the help - see update fiddle

I was going mad…

This is the solution - Issue with my project

I thought the same at first and I was going to point that out. But you can’t use any operators in switch. You can assign those values to a variable and then instead pass in that variable to the switch.

1 Like

Yeah just was tired of looking at the same bit of code and not seeing the actual issue. That can happen right?! Thanks again for help :slight_smile:

1 Like

Of course. Through time you’ll get better at debugging your code and deciding when to take a refresher. Before the syntax, I recommend you always check the logic of your code first. Syntax errors will be easier to fix then. Or not depends on how the actual problem reveals itself. Hopefully a not too hard problem.

Anyways I’m glad to be of help. Happy Coding!

1 Like

Thanks for the help mate :slight_smile:

Not true, this works:

1 Like

I see. Good to know then.

1 Like