El resultado tiene que salir 15.
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Juego</title> <script> function validarjuego(){ //obteniendo valores de las 9 casillas aa = parseInt(document.formulario.AA.value); ab = parseInt(document.formulario.AB.value); ac = parseInt(document.formulario.AC.value); ba = parseInt(document.formulario.BA.value); bb = parseInt(document.formulario.BB.value); bc = parseInt(document.formulario.BC.value); ca = parseInt(document.formulario.CA.value); cb = parseInt(document.formulario.CB.value); cc = parseInt(document.formulario.CC.value); //fin de obtencion de valores s = new Array(); s[0]= ca+bb+ac; s[1]= aa+ab+ac; s[2]= ba+bb+bc; s[3]= ca+cb+cc; s[4]= aa+bb+cc; s[5]= ac+bc+cc; s[6]= ab+bb+cb; s[7]= aa+ba+ca; document.formulario.S1.value = s[0]; document.formulario.S2.value = s[1]; document.formulario.S3.value = s[2]; document.formulario.S4.value = s[3]; document.formulario.S5.value = s[4]; document.formulario.S6.value = s[5]; document.formulario.S7.value = s[6]; document.formulario.S8.value = s[7]; n=0; x=1; while(n<=7){ if(s[n]==15){ x+=1; } n++; } if(x>=8){ alert('Ganastes!'); }else{ alert('Perdiste...'); } } </script> </head> <body> <form name="formulario"> <table width="400" border="1" align="center"> <tr> <td colspan="3"><h1>Juego</h1></td> <td width="111" bgcolor="#CCCCCC">= <input name="S1" type="text" id="S1" size="10" /></td> </tr> <tr> <td width="88"><input name="AA" type="text" id="AA" size="10" /></td> <td width="88"><input name="AB" type="text" id="AB" size="10" /></td> <td width="85"><input name="AC" type="text" id="AC" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S2" type="text" id="S2" size="10" /></td> </tr> <tr> <td><input name="BA" type="text" id="BA" size="10" /></td> <td><input name="BB" type="text" id="BB" size="10" /></td> <td><input name="BC" type="text" id="BC" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S3" type="text" id="S3" size="10" /></td> </tr> <tr> <td><input name="CA" type="text" id="CA" size="10" /></td> <td><input name="CB" type="text" id="CB" size="10" /></td> <td><input name="CC" type="text" id="CC" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S4" type="text" id="S4" size="10" /></td> </tr> <tr> <td bgcolor="#CCCCCC">= <input name="S8" type="text" id="S8" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S7" type="text" id="S7" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S6" type="text" id="S6" size="10" /></td> <td bgcolor="#CCCCCC">= <input name="S5" type="text" id="S5" size="10" /></td> </tr> <tr> <td colspan="4" bgcolor="#CCCCCC"><div align="center"> <input name="Botón" type="button" value="Validar" onclick="validarjuego()"/> </div></td> </tr> </table> </form> </body> </html>