I'm learning JS, and in my practice I can't get the second part of my script to work for me.
I have 3 inputs (#ancho - #fondo - #alto
), where I write integers number for a multiplication between them, followed by a division. This part works fine
Now the problem:
In the second part, I want to compare if the value "r =" is greater or less than the number written (por the user) in the input #peso
, but it doesn't work for me.
What am I doing wrong here?
See the DEMO in JSFiddle
Thanks in advance!
HTML:
<input id="ancho"> <!-- Example value="22" -->
<input id="fondo"> <!-- Example value="20" -->
<input id="alto"> <!-- Example value="16" -->
<input id="peso"> <!-- Example value="3" -->
<div id="resultado"></div>
<div id="hacercalculo" onclick="calcular();comparar()">Calcular</div>
<!--css display none-->
<div id="uno">1</div>
<div id="dos">2</div>
<div id="tres">3</div>
jQuery:
https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js
Script:
// Calculate - This part works fine
function calcular(){
v1 = document.getElementById("ancho").value;
v2 = document.getElementById("fondo").value;
v3 = document.getElementById("alto").value;
r = v1*v2*v3/4000;
//document.getElementById("resultado").value = r;
document.getElementById("resultado").innerHTML = r;
};
//=============
// Compare - This, It does not work for me
function comparar() {
var camp1= document.getElementById("resultado");
var camp2= document.getElementById("peso");
//if (camp1.value >= 0 && camp2.value <= 3) {
//if (camp1.innerText >= 0 && camp2.innerText <= 3) {
//if (camp1.innerHTML >= 0 && camp2.value <= 3) {
if (camp1.innerText >= 0 && camp2.value <= 3) {
$("#uno").show(); // This, It does not work for me
}
};