My ugly RPS game (works but not pretty)


#1

This is probably way too much code for such a simple game.

How do I do if comparisons without a function? To make it work, I made a function withe the (domath) parameter. But I don't actually need that parameter to do anything, it was just the only way I knew how to continue with if, if else, else, statements.

You'll see the end line is undefined, since (domath) is not defined anywhere. How do I fix this?

var myMove = prompt("1,2,3....rock, paper, scissors?")
console.log("You throw" + " " + myMove)

var Comp = Math.floor((Math.random() * 3) + 1);{
if (Comp == 1){
Comp = "rock";
}
else if (Comp == 2){
Comp = "paper";
}
else {
Comp = "scissors";
}
}
console.log("RPSBot throws" + " " + Comp)

var Results = function(domath){
if (myMove == "rock"){
if (Comp == "rock"){
console.log("It's a tie")
}
else if (Comp == "scissors") {
console.log("Your rock crushes scissors!")
}
else {
console.log("Paper covers your rock")
}}
else if (myMove == "paper"){
if (Comp == "paper"){
console.log("It's a tie")
}
else if (Comp == "rock"){
console.log("Your paper covers rock")
}
else {
console.log("Scissors cut your paper")
}}
else {
if (Comp == "scissors"){
console.log("It's a tie")
}
else if (Comp == "paper"){
console.log("Your scissors cuts paper!")
}
else {
console.log("Rock crushes your scissors")
}}
}
console.log(Results("domath"));


#2

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);
var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is a tie!";
}
else if(choice1 === "rock")
if(choice2 === "scissors") {
return "Rock wins"
}
else {
return "Paper wins"
}
else if(choice1 === "paper")
if(choice2 === "rock") {
return "Paper wins"
}
else {
return "Scissors wins"
}
else if(choice1 === "scissors")
if(choice2 === "rock") {
return "Rock wins"
}
else {
return "Scissors wins"
}
};
compare(userChoice, computerChoice)

Now I believe the most of your code came from the force to repeat the "tie" result when all you had to say is that when that are equal it is a tie. Also you had your two options as one option and I don't understand how that worked or why to do that over keeping them separate but oh well.