Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

98
Views
Intentando hacer una calculadora con javascript pero no da ningún resultado

Estoy practicando declaraciones if y estoy tratando de hacer una calculadora. Puedo ingresar los números pero hacer clic en los botones de sumar, restar, multiplicar o dividir no me da ningún resultado. Sé que hay formas más fáciles de hacerlo, pero fue solo para practicar. ¿Qué he hecho mal?

 function operar(boton) { var num1, num2, resultado; num1 = document.getElementById("num1"); num2 = document.getElementById("num2"); resultado = document.getElementById("resultado"); if (boton.value == '+') { resultado.value = Number(num1.value) + Number(num2.value); } else { if (boton.value == '-') { resultado.value = Number(num1.value) - Number(num2.value); } else { if (boton.value == '*') { resultado.value = Number(num1.value) * Number(num2.value); } else { if (boton.value == '/') { resultado.value = Number(num1.value) / Number(num2.value); } } } } }
 <form> <div> <label>Número 1</label> <input id="num1" type="text" /> </div> <div> <label>Número 2</label> <input id="num2" type="text" /> </div> <input type="button" value="+" onclick="operar(this)" /> <input type="button" value="-" onclick="operar(this)" /> <input type="button" value="*" onclick="operar(this)" /> <input type="button" value="/" onclick="operar(this)" /> <div> <label>Resultado</label> <input type="text" id="resultado" /> </div> </form>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El fragmento que diste aquí, este código funciona perfectamente. ¿Qué más quieres hacer?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!