Rock,paper,scissors, bugging.. JavaScript


Can anyone please tell me why is this allways returning "The result is a tie!" what ever the input... ??

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";


because when you call the function:


you don't supply any arguments for the parameters


okkk.... so how do i fix that? im pretty sure this is the way they instructed me to do it..


you learned about parameters and arguments:

arguments is what you supply at function call to satisfy the parameters


yes, but is't the Prompt satisfying the parameter in this one? can u please just post me the this code fixed... i'm sure i'l figure it out my self, i would be very grateful!


your function has two parameters:

var compare = function(choice1,choice2)

so at function call you should supply two arguments:

console.log(compare(argument1, argument2))

the values of the argument get copied into the function parameter


welll thank you very much friend..... that make's it much clearer...


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