# Would you help a complete beginner? (rock-paper-scissors-lizard-spock game)

• 01-10-2014, 12:09 AM
SHa
Would you help a complete beginner? (rock-paper-scissors-lizard-spock game)
Hello!
i just started to learn Javascript and i tried to write a rock - paper - scissors - lizard - Spock game,
it doesn't return the right answers.
what have i done wrong? the nesting? the math.random()? :confused:

here's the code:

var userChoice = prompt("Do you choose rock, paper, scissors, lizard or spock?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice < 0.20)
computerChoice = "rock";
else
if(computerChoice <= 0.40)
computerChoice = "paper";
else
if(computerChoice <= 0.60)
computerChoice = "scissors";
else
if(computerChoice <= 0.80)
computerChoise = "lizard";
else
if(computerChoice <= 1)
computerChoice = "spock";

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
if(choise2 == "paper")
return("paper wins");
else
if(choice2 == "lizard")
return("rock wins");
else
if(choice2 == "spock")
return ("spock wins");
else
if (choice1 == "paper")
if (choice2 == "rock")
return("paper wins");
else
if(choice2 == "scissors")
return("scissors wins");
else
if(choice2 == "lizard")
return ("lizard wins");
else
if(choice2 == "spock")
return("paper wins");
else
if (choice1 == "scissors")
if (choice2 == "rock")
return("rock wins");
else
if(choice2 == "paper")
return("scissors wins");
else
if(choice2 == "lizard")
return("scissors wins");
else
if(choice2 == "spock")
return("spock wins");
else
if (choice1 == "lizard")
if (choice2 == "rock")
return("rock wins");
else
if(choice2 == "paper")
return("lizard wins");
else
if(choice2 == "scissors")
return("scissors wins");
else
if(choice2 == "spock")
return("lizard wins");
else
if (choice1 == "spock")
if (choice2 == "rock")
return("spock wins");
else
if(choice2 == "paper")
return("paper wins");
else
if(choice2 == "lizard")
return("lizard wins");
else
if(choice2 == "scissors")
return("spock wins");
};

compare(computerChoice, userChoice);
• 01-10-2014, 04:29 AM
tech_soul8
I have always hated the answers like the one I'm going to give to you but the fact that this issue (making rock-paper-scissors game) was already discussed many times before I would suggest you use the search function of the forum.
• 01-10-2014, 04:58 AM
\\.\
Yep, not the first, nor the last and in the spirit of the great Spock, go forth and you will find what you seek.

## X vBulletin 4.2.2 Debug Information

• Page Generation 0.21404 seconds
• Memory Usage 2,354KB
• Queries Executed 11 (?)
Template Usage (19):
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates