9/9 Trying to make the game more advance


#1

So now when chooce1 === chooce2 we get a message "The result is a tie! Choose again" but I don't want the game to end here, I want the prompt straight away to jump out and ask me again what to choose. So instead of
var compare = function (choice1, choice2) {

if (choice1 === choice2) {
return "The result is a tie! Choose again";

I write:

return ("The result is a tie! Choose again" + userChoice);

userChoice here is var = prompt which asks user to choose rock, paper, scissors. But when I get choice1 === choice2 it just prints out "The result is a tie! Choose again" together with the last choice I typed in the prompt so for example if I chose rock and results were choice1 === choice2 it will say "The result is a tie! Choose again rock" How can I make it ask me to type a chose again?


#2

I think we could make a function in this function you call your prompt
Than call the function in your if.


#3

Think of it in component terms. We have a compare module, but lack any other modules, for the present, since our code is a run once script. We might look at it like so,

  1. User input module
  2. Computer input module
  3. Compare module
  4. Control module

The first three are essentially utility and need only be generic functions. They should all return a value to the caller, and not have any references to global scope. The control module is the main scope within which the program will run. If we put this inside a function, there will be no interference with or from the global scope.

Chew on that for a minute. We will solve this in due course of time. We have our parameters, now let's set out to write a proof of concept. I'll start by blocking what we proposed so far...

function you(){
}
function me(){
}
function compare(u, m){
}
function main(){
    compare(you(), me());
}
main();

Ponder on this...