Rock Paper Scissors Tutorial site Error


#1

I completed the course on “How to Make a Game of Rock Paper, Scissors.” It said I did it, and that I completed the course, but I did not actually succeed in creating a game of Rock, Paper, Scissors. I created something that runs a calculation of between 0 and 1 then tells me what it rolled and assigned it a value above a string of potentially useful and entirely unused code.that actually gives what you chose as rock, paper, or scissors value. There is no bridge between them and no link to what you chose as userChoice and no message letting you know you won. This needs to be addressed as a site, I feel, as I only caught it after realizing that though it said I made a game, complete with a brand new badge, I only succeeded in creating something useless while potentially_thinking_ I learned how to create a game now. Help me figure out how to make an actual game of R/P/S. I’d really appreciate any help you can give me as a new programmer. Also, to those this applies to, could you fix things so we learn how to make an actual game as the tutorial suggests?


var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer:" + computerChoice);
/*This IS NOT a true game of Rock Paper Scissors. It it totally unconnected to userChoice and displays no "who won" sign. Fix. Programs ends here as of right now. It needs to connect to the code below, have some sort of method of calling it into action and integrating it. Right now, it only runs a 0 - 1 and tells us what it did as Computer: 0 - 1.*/
var compare = function(choice1, choice2 )

//This IS NOT a true game of Rock Paper Scissors. It it totally unconnected to userChoice and displays no "who won" sign. Fix. 
{
    if (choice1 === choice2)
        return "The result is a tie!";
    
    else if(choice1 === "rock") 
        {
        if(choice2 === "scissors") 
    
            return "rock wins";
        }
        else if(choice2 === "paper")
        {
            return "paper wins";
        }

    else if(choice1 === "paper")
        {
        if(choice2 === "rock")
            return "paper wins";
        }
        else if(choice2 === "scissors")
            return "scissors wins";
    else if(choice1 === "scissors")
        {
        if(choice2 === "paper")
            return "scissors wins";
        }
        else if(choice2 === "rock")
        {
            return "rock wins";
        }
                if(computerChoice < 0.34)
                    {
                    console.log("Rock wins!");
                    }
        
}




#2

a function only executes when called, so in order for your program to fully work, a single line of code is needed ( a function call)

this connects everything, then output is displayed and everything

you might want to use console.log() as well, to log the returned result by the function


#3

How do I do that in this circumstance? I’m very much a neophyte at coding, I need all the pointers I can get. I appreciate your help, thanks.


#4

if you need all the pointers, for JS, there is this great documentation website (MDN), which also has information on function and function calls:


#5

I’ve been looking up tutorials, syntax stuff, etc. What I was looking for, and what I need is someone to tell me what and where to put as a call. I used What am I calling, exactly-- compare? I’m very frustrated here – the tutorial I depend on for teaching me this stuff says I did it correctly when that is clearly not the case and I tried putting:

compare(userChoice, computerChoice);

in at the last line, but it only ever says the computer made a choice, which does nothing to actually make a game of rock, paper, scissors. I don’t know why the site says “Congratulations! You finished the course!” when I didn’t actually learn anything and I have no idea what I’m doing wrong. Please, somebody, tell me what I’m doing wrong and what I can do right in the future.


#6

But if you needed/wanted help with placing the function call, and you attempted to call the function, you should show me

now i assumed you struggled with: how is the syntax for a function call (which is the next logical problem you could encounter)

how and where did you place the function call? Show me

given the function returns, you might want to use console.log() to log the returned result to the console


#7

I think I figured it out. Thanks!


#8

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