Make a rock, paper, scissor game


#1


Use this code. It takes a lot of my time to debug.. Check this let me know about any error!

var choices = ["rock", "paper", "scissors"];
var choices = ["rock", "spock", "paper", "lizard", "scissors"];

function mod(a, b) {
    c = a % b
    return (c < 0) ? c + b : c
}

function compare(choice1, choice2) {
    x = choices.indexOf(choice1);
    y = choices.indexOf(choice2);
    if (x == y) {
        return "Tie";
    }
    if (mod((x - y), choices.length) < choices.length / 2) {
        return choice1 + " wins";
    } else {
        return choice2 + " wins";
    }
}

var result = ""

for (i in choices) {
    for (j in choices) {
        left = choices[i];
        right = choices[j];
        result += left + " " + right + " " + compare(left, right) + "\n";
    }
}

console.log(result);


#2

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