New to programming, copied the program as it is through a youtube tutorial, but still getting an error and unable to find the solution.
ERROR = 0: Unable to get property 'PAPER' of undefined or null reference
java.js (52,4)
Program:
function LOL(yourchoice){
console.log(yourchoice.id);
var humanchoice, botchoice;
humanchoice = yourchoice.id;
botchoice = num(random());
console.log("Computer Choice:", botchoice);
result = decidewinner(humanchoice, botchoice) ;
console.log(result);
message = finalmessage(result);
console.log(nessage);
}
function random(){
return Math.floor(Math.random()*3);
}
function num(number){
return ["ROCK", "PAPER", "SCISSORS"][number];
}
function decidewinner(yourchoice, computerchoice){
var database = {
"ROCK": {"SCISSORS":1, "ROCK":0.5, "PAPER":0 },
"PAPER": {"SCISSORS":0, "ROCK":1, "PAPER":0.5 },
"SCISSORS": {"SCISSORS":0.5, "ROCK":0, "PAPER":1 },
};
LINE 52:
var yourscore = database[yourchoice][computerchoice];
var computerscore = database[computerchoice][yourchoice];
return [yourchoice, computerscore];
}
function finalmessage([yourscore, computerscore]){
if (yourscore=== 0){
return ("Message:", "You LOST!", 'color:','red');
};
if (yourscore===1){
return("Message:", "Hurray! You WON", "color:", "blue");
} else{
return("Message:", "TIED!", "color:", "yellow");
}
}
What I have tried:
Tried to check line 52 of javascript code but there is no code there.
Also, tried the whole program again 3 times, still facing same issue.