Foros del Web » Programando para Internet » Javascript »

Memory game Comprobar

Estas en el tema de Memory game Comprobar en el foro de Javascript en Foros del Web. Hola tengo problema con mi codigo no logro hacer que al introducir los valores en la funcion comp(); sea = a true , en cambio ...
  #1 (permalink)  
Antiguo 21/04/2015, 20:07
 
Fecha de Ingreso: abril-2015
Mensajes: 1
Antigüedad: 9 años
Puntos: 0
Memory game Comprobar

Hola tengo problema con mi codigo no logro hacer que al introducir los valores en la funcion comp(); sea = a true , en cambio simpre salta el fallaste intenta nuevamente y no se por que es el error agrasco la ayuda es un reto.
Código HTML:
	//Declare a function for get the value of the amount of the digits  //
	var rando;

	function envia() {
	var numero=document.getElementById('num').value;
	

	// Random numbers  //

	if (numero == 2){
		 rando=Math.floor(Math.random()*90)+9;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $('#caja').fadeOut(1000);
		 
	}
		else if (numero == 3){
		 rando=Math.floor(Math.random()*900)+99;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
		else if (numero == 4){
		 rando=Math.floor(Math.random()*10000)+999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });

	}
		else if (numero == 5){
		 rando=Math.floor(Math.random()*100000)+9999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
		else if (numero == 6){
		 rando=Math.floor(Math.random()*100000)+99999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
		else if (numero == 7){
		 rando=Math.floor(Math.random()*1000000)+999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
		else if (numero == 8){
		 rando=Math.floor(Math.random()*10000000)+9999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
		else if (numero == 9){
		 rando=Math.floor(Math.random()*100000000)+99999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
	else if (numero == 10){
		 rando=Math.floor(Math.random()*1000000000)+999999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
	else if (numero == 11){
		 rando=Math.floor(Math.random()*10000000000)+9999999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
	else if (numero == 12){
		 rando=Math.floor(Math.random()*100000000000)+999999999999;
		 rando=Number(rando);
		 var caja=document.getElementById('caja').innerHTML=rando;
		 $(function(){
		 	$('#caja').fadeOut(1000);
		 });
	}
}



/*=============Compare the Values============*/


  function comp()
    {
        var caja=document.getElementById('caja').value;
        var k=document.getElementById('k').value;

        k=Number('k');
        caja=Number('caja');

        if (k == rando){
            alert("You have a very good memory");
        }else{
            alert("I'm sorry Try angein");
        }
    }

/*=============Show the Numbers============*/

 function mostrar(){	
 	 
 	 $(function(){
 	 	$('#caja').fadeIn('slow');
 	 });
 }
  #2 (permalink)  
Antiguo 22/04/2015, 08:00
Colaborador
 
Fecha de Ingreso: septiembre-2013
Ubicación: España
Mensajes: 3.648
Antigüedad: 10 años, 7 meses
Puntos: 578
Respuesta: Memory game Comprobar

Estabas pasando el argumento como string, no como variable, por lo tanto siempre te da NaN:

Código Javascript:
Ver original
  1. k = Number(k);
  2. caja = Number(caja);

Etiquetas: funcion, game, html, memory, valor
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:37.