JavaScript - como hago para indicar si un numero es mayor que otro?

 
Vista:
sin imagen de perfil

como hago para indicar si un numero es mayor que otro?

Publicado por anonymous (50 intervenciones) el 05/06/2016 00:34:22
lo que pasa con el código es que le pongo que si es mayor este numero en algunos casos dice que es mayor que otro numero siendo mentira a veces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@font-face {
font-family: calc;
src: url(calc.ttf);}
select {width: 60%;font-size:18px;height: 30px;padding:0px;margin: 0px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;-moz-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;background:linear-gradient(#342E21,#483F2E);color:rgba(0,0,0,1.00);border:none;display: inline-block;cursor:pointer;}
input{color: #fff; font-size: 18px;}
select:not(:checked) {
    background-color:#342E21;
    color:#fff;}
input[type=number]::-webkit-inner-spin-button {-webkit-appearance: none;margin: 0;}
input[type=number] {-moz-appearance:textfield;}
hr {  border: 1px dotted #fff;}
select {width: 60%;font-size:18px;height: 30px;padding:0px;margin: 0px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;-moz-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;background:linear-gradient(#342E21,#483F2E);color:rgba(0,0,0,1.00);border:none;display: inline-block;cursor:pointer;}
.calculapitagoras{border-radius:12px; background:rgba(58,58,60,1.00);}
.txtr1{font-family: calc; width: 60%;font-size:18px;height: 30px;padding:0px;margin: 0px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;-moz-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;background:linear-gradient(#342E21,#483F2E); color:rgba(255,255,255,1.00);border:none;display: inline-block;}
.txtr{font-family: calc; width: 40%;font-size:18px;height: 30px;padding:0px;margin: 0px;-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px;-webkit-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;-moz-box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;box-shadow: 0 0px 0 #ccc, 0 0px #fff inset;background:linear-gradient(#342E21,#483F2E); color:rgba(255,255,255,1.00);border:none;display: inline-block;}
.button{ cursor:pointer;border-radius:5px; height:30px; width:90px; background-color:#11B547; border-color:rgba(0,0,0,0.00)}
.button:hover{background-color: #11A536}
@media screen and (min-width : 0px ) and (max-width : 450px){
select{ width:55%;}
.txtr{width:100%;}}
@media screen and (min-width : 0px ) and (max-width : 300px){
select{ width:60%;}
.txtr{width:100%;}}
</style>
<script type="text/javascript">
   function limpiar(){
     navigator.vibrate([50, 250]);
     document.calculator.txtnum1.value="";
     document.calculator.txtnum2.value="";
     document.calculator.txtresultado.value="";
     document.getElementById("lblnum1").innerHTML="";
   }
    function pitagoras(){
	  	var y = document.getElementById("seleccion").options;
      var x = document.getElementById("seleccion").selectedIndex;
	    var n1=document.calculator.txtnum1.value;
    	var n2=document.calculator.txtnum2.value;
      navigator.vibrate([50, 250]);
	switch (y[x].index){
	case 0:
	    potencia=Math.pow(n2,2)-(Math.pow(n1,2));
    	resultado1=Math.sqrt(potencia);
		resultado2=Math.round(resultado1 * 100) / 100;
	    document.calculator.txtresultado.value=resultado2;
 
      if((n1=="")||(n2=="")){
        alert("por favor llena los campos de texto");
        limpiar();
      }
		break;
	case 1:
	    potencia2=Math.pow(n1,2)-(Math.pow(n2,2));
    	resultado=Math.sqrt(potencia2);
	    document.calculator.txtresultado.value=resultado;
		resultado1=Math.round(resultado * 100) / 100;
	    document.calculator.txtresultado.value=resultado1;
      if((n1=="")||(n2=="")){
        alert("por favor llena los campos de texto");
        limpiar();
      }
		 break;
	case 2:
	    potencia2=Math.pow(n1,2)+(Math.pow(n2,2));
    	resultado=Math.sqrt(potencia2);
	    document.calculator.txtresultado.value=resultado;
		resultado1=Math.round(resultado * 100) / 100;
	    document.calculator.txtresultado.value=resultado1;
      if((n1=="")||(n2=="")){
        alert("por favor llena los campos de texto");
        limpiar();
      }
		break;
		}}
function texto() {
        navigator.vibrate([50, 250]);
        var y = document.getElementById("seleccion").options;
        var x = document.getElementById("seleccion").selectedIndex;
     switch (y[x].index){
        case 0:
		document.getElementById("demo1").innerHTML="Cateto b:";
        document.getElementById("demo2").innerHTML="Hipotenusa c:";
		document.getElementById("demo3").innerHTML="Cateto a:";
        break;
        case 1:
      document.getElementById("demo1").innerHTML="Hipotenusa c:";
        document.getElementById("demo2").innerHTML="Cateto a:";
		document.getElementById("demo3").innerHTML="Cateto b:";
        break;
        case 2:
        document.getElementById("demo1").innerHTML="Cateto a:";
        document.getElementById("demo2").innerHTML="Cateto b:";
		document.getElementById("demo3").innerHTML="Hipotenusa c:";
		break;
}}
function operaciones() {
           var y = document.getElementById("seleccion").options;
           var x = document.getElementById("seleccion").selectedIndex;
           var n1=document.calculator.txtnum1.value;
           var n2=document.calculator.txtnum2.value;
           var n3=document.calculator.txtresultado.value;
        switch (y[x].index){
           case 0:
           if(n1<n2) {
          document.getElementById("lblnum1").innerHTML=
           "<b>Procedimiento</b><br>"+
           "a<sup>2</sup>"+" = "+n1+"<sup>2</sup>" +" - "+ n2+"<sup>2</sup><br>"+
           "a<sup>2</sup>"+ " = " + Math.pow(n1,2)+" - "+Math.pow(n2,2)+"<br>"+
           "a<sup>2</sup>" + " = " + (Math.pow(n2,2)-Math.pow(n1,2)) + "<br>"+
           "a"+ " = " +"√  "+"(" + (Math.pow(n2,2)-Math.pow(n1,2)) + ")" + "<br>"+
           "<span style='color:#000;background-color:rgba(255,237,0,0.80);'>" + "a" + " = " +  (Math.sqrt(Math.pow(n2,2)-Math.pow(n1,2))) +"</span>";
         }
           if (n1>n2) {
           alert("La hipoteusa debe de ser mas grande");
           limpiar();
         }
           break;
           //b2=c2-a2
           case 1:
           if(n1>n2){
          document.getElementById("lblnum1").innerHTML=
           "<b>Procedimiento</b><br>"+
           "b<sup>2</sup>"+" = "+n1+"<sup>2</sup>" +" - "+ n2+ "<sup>2</sup><br>"+
           "b<sup>2</sup>"+ " = " + Math.pow(n1,2) +" - " + Math.pow(n2,2)+"<br>"+
           "b<sup>2</sup>" + " = " + (Math.pow(n1,2)-Math.pow(n2,2)) + "<br>"+
           "b"+ " = " +"√ "+"(" + (Math.pow(n1,2)-Math.pow(n2,2)) + ")" + "<br>"+
            "<span style='color:#000;background-color:rgba(255,237,0,0.80);'>"+"b" + " = " +  (Math.sqrt(Math.pow(n1,2)-Math.pow(n2,2)))+"</span>";
          }
          if(n1<n2){
            alert("La hipoteusa debe de ser mas grande");
            limpiar();
          }
           break;
           case 2:
          document.getElementById("lblnum1").innerHTML=
           "<b>Procedimiento:</b><br><b>Hipotenusa C</b><br>"+
           "c<sup>2</sup>"+" = "+n1+"<sup>2</sup>" +" + "+ n2+"<sup>2</sup><br>"+
           "c<sup>2</sup>"+ " = " + Math.pow(n1,2)+" + "+Math.pow(n2,2)+"<br>"+
           "c<sup>2</sup>" + " = " + (Math.pow(n2,2)+Math.pow(n1,2)) + "<br>"+
           "c"+ " = " +"√ "+"(" + (Math.pow(n2,2)+Math.pow(n1,2)) + ")" + "<br>"+
           "<span style='color:#000;background-color:rgba(255,237,0,0.80);'>" + "c" + " = " +
           (Math.sqrt(Math.pow(n2,2)+Math.pow(n1,2)))+"</span><br>"+"<b>Angulo B </b><br>Sin B^= " + n2+" ÷ "+n3+
           "<br>Sin B^= " +n2/n3+"<br>"+
"B^= sin<sup>-1</sup>("+n2/n3+")<br><span style='color:#000;background-color:rgba(255,237,0,0.80);'> B^= "+ Math.asin(n2/n3)*180/Math.PI+</span><br><b>Angulo C </b><br><span style='color:#000;background-color:rgba(255,237,0,0.80);'>C^= 90º</span><br><b>Angulo A </b><br>A^= 90º - "+Math.asin(n2/n3)*180/Math.PI+<br><span style='color:#000;background-color:rgba(255,237,0,0.80);'>A^= "+(90-Math.asin(n2/n3)*180/Math.PI)+</span>";
      break;
   }}
</script>
<link href="estilo.css" rel="stylesheet" type="text/css"/>
<title>Teorema de pitagoras</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<!--  Chrome, Firefox OS y Opera  -->
 <meta name="theme-color" content="#2CBBDF"/>
 <!--  Windows Phone  -->
 <meta name="msapplication-navbutton-color" content="#2CBBDF"/>
 <!--  iOS Safari  -->
<meta name="apple-mobile-web-app-capable" content="#2CBBDF"/>
<meta name="apple-mobile-web-app-status-bar-style" content="#2CBBDF"/>
<link rel="shortcut icon" href="ico.png"/>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
</head>
<body onload="texto()">
<div id="titulopag"><a itemprop="url" class="enlace3 titulopag" href="inicio" target="_blank"></a></div><a href="inicio"><div class="inicio" title="Inicio">Incio</div></a><a href="Contenido"><div class="contenido" title="Contenido">Contenido</div></a><a href="Acerca_de"><div class="acercade" title="Acerca de">Acerca de</div></a>
<div class="panelizq">
  <div class="investigacion">
  <h1 class="titulo">
  <span style="color: #FF00FF">!</span><span style="color: #FF3300">Sa</span><span style="color: #CCFF00">bi</span><span style="color: #2CA3E5">as</span>
  <span style="color:#42D93B">que</span><span style="color: #FF0000">?</span>
  </h1>
     • los angulos son en mayuscula (a mi me dijeron asi) para no confundir con los lados.
</div></div>
<div class="paneldere">
<ul><li>
</li></ul>
</div>
<p></p>
<div class="informacion">
  <div class="investigacion">
    <h1>Calculadora de Teorema de Pitágoras</h1>
    <center><img src="teorema_pitagoras_files/imagenes/teorema-pitagoras.png" alt="imagen no disponible" /></center>
  <p>Gracias al teorema de Pitágoras sabemos que el valor de la hipotenusa al cuadrado de cualquier triángulo rectángulo es igual a la suma de los cuadrados de los catetos. Esto se aprecia de forma visual y matemática en la imagen que tienes arriba en la cual se pueden ver los catetos ‘a’ y ‘b’ junto con la hipotenusa ‘c’ que corresponde con el lado de mayor longitud.</p>
<p>Si quieres calcular el valor de cualquier lado del triángulo rectángulo conociendo los otros dos, ahora puedes hacerlo gracias a mi!! calculadora del Teorema de Pitágoras con Procedimientos: </p>
    <form name="calculator" class="calculapitagoras">
    <div class="investigacion">
    <br>
    <span style="color: #fff; font-family:calc;font-weight: bold; font-size:32px;">Calculadora Pitágoras</span>
     <hr>
     <span style="color: #fff; font-family:calc; font-size:18px;">
¿Que quieres calcular?<br>
<select id="seleccion" onchange="texto();">
 <option>Cateto a</option>
 <option>Cateto b</option>
 <option>Hipotenusa c</option>
 </select>
<br><br>
<label id="demo1"></label>
<br>
<input class="txtr" type="number" name="txtnum1" autocomplete="off">
 <br><br>
<label id="demo2"></label>
 <br>
 <input class="txtr" type="number"  name="txtnum2" autocomplete="off">
 <br><br>
 <input type="button" class="button" value="Calcular" onClick="pitagoras();operaciones();">
 <input type="button" class="button" value="Limpiar" onClick="limpiar()">
 <br>
<hr>
<label id="demo3"></label>
<br>
 <input class="txtr1" type="number" autocomplete="off" name="txtresultado">
 <br>
  <hr>
 <label id="lblnum1">
 </label>
 </span>
</div>
 <br>
 </form>
  </div>
  <br>
</div>
<a href="#" class="scrolltop" style="display: block;"><img src="flecha-top.png" width="50" height="50" alt=""/></a>
<div class="abajo">
<span class="panelbuttom">Fecha de edicion: 6 de Mayo del 2016</span>
<span class="panelbuttomc">Editor: Humberto Molina Lopez</span>
</div>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

como hago para indicar si un numero es mayor que otro?

Publicado por xve (2100 intervenciones) el 05/06/2016 09:10:05
Hola Humberto, que valores tengo que poner para que me de un valor erróneo?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

como hago para indicar si un numero es mayor que otro?

Publicado por anonymous (50 intervenciones) el 05/06/2016 11:40:44
no te preocupes yalo resolvi pronto te pasare el script del pitagoras :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar