Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-25-2012, 01:46 AM   PM User | #1
memo333
New to the CF scene

 
Join Date: Oct 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
memo333 is an unknown quantity at this point
Question scissors cant win vs paper :(

Code:

function ppt()
{
	

var userChoice = prompt("Escoje piedra, papel o tijeras");

var computerChoice = Math.random();

if (computerChoice <0.34){

computerChoice = "piedra";
}else if(computerChoice <=0.67){
computerChoice = "papel";
}else{
computerChoice = "tijeras";
}



function comparar(choice1,choice2){

if(choice1===choice2){return alert("EMPATE!");}//empate


if (choice1==="piedra"&&choice2=== "tijeras"){return alert("GANASTE");}
else{return alert("PERDISTE!");}


if (choice1==="papel"&&choice2=== "tijeras"){return alert("PERDISTE");}
else{return alert("GANASTE!");}


if (choice1==="tijeras"&&choice2=== "piedra"){return alert("PERDISTE!");}
else{return alert("GANASTE");}



}//fin funcion comparar

comparar(userChoice,computerChoice);

alert("Tu elejiste " +userChoice +" y la computadora elijio " +computerChoice); 




}//fin de funcion ppt
memo333 is offline   Reply With Quote
Old 10-25-2012, 01:11 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Your very first comparison
Code:
if (choice1==="piedra"&&choice2=== "tijeras"){return alert("GANASTE");}
else{return alert("PERDISTE!");}
means: Only return "GANASTE", if choice1 is piedra and choice2 is tijeras, in EVERY OTHER CASE it will return "PERDISTE" and will never do the other checks.

Try this
Code:
if ((choice1==="piedra"&&choice2=== "tijeras")||(choice1==="papel"&&choice2=== "tijeras")||(choice1==="tijeras"&&choice2=== "piedra")){return alert("GANASTE");}
else{return alert("PERDISTE!");}
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:20 AM.


Advertisement
Log in to turn off these ads.