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

170
Views
La calculadora no funciona, no puedo encontrar el problema (mecanografiado)

Tengo que programar una calculadora para mi clase. No soy muy bueno en esto, así que lo hice exactamente como lo hicimos en clase, pero no funciona y no puedo encontrar el problema. No estoy buscando la solución completa, solo un consejo sobre dónde está el problema.

La calculadora consta de 2 campos de entrada para los números y 1 botón para sumar los números

 HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="node_modules"></script> <script src="script.js"></script> </head> <body> <label for="zahl1"></label> <input id="zahl1" type="text" placeholder="Zahl eingeben"> <label for="zahl2" type="text"></label> <input id="zahl2" type="text" placeholder="Zahl eingeben"> <button id="plusBtn" class="btn btn-info">+</button> <p id="ergebnis"></p> </body> </html> Typescript document.addEventListener("DomContentLoaded", () => { document.getElementById("plusBtn").addEventListener("click", () => { const zahl1Input = document.getElementById("zahl1") as HTMLInputElement; const zahl2Input = document.getElementById("zahl2") as HTMLInputElement; const zahl1: number = Number(zahl1Input.value); const zahl2: number = Number(zahl2Input.value); const sum = zahl1 + zahl2 let ergebnis: number; ergebnis = sum(zahl1, zahl2) const ergebnisInput = document.getElementById("ergebnis") as HTMLInputElement; ergebnisInput.value = ergebnis.toString(); }) })
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Arreglé el código. Compara las diferencias...

 window.addEventListener("DOMContentLoaded", () => { document.getElementById("plusBtn").addEventListener("click", () => { const zahl1Input = document.getElementById("zahl1"); const zahl2Input = document.getElementById("zahl2"); const zahl1 = Number(zahl1Input.value); const zahl2 = Number(zahl2Input.value); const sum = zahl1 + zahl2 let ergebnis; ergebnis = sum const ergebnisInput = document.getElementById("ergebnis"); ergebnisInput.innerText = ergebnis.toString(); }) })
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <script src="node_modules"></script> <script src="script.js"></script> </head> <body> <label for="zahl1"></label> <input id="zahl1" type="text" placeholder="Zahl eingeben"> <label for="zahl2" type="text"></label> <input id="zahl2" type="text" placeholder="Zahl eingeben"> <button id="plusBtn" class="btn btn-info">+</button> <p id="ergebnis"></p> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

ergebnis = sum(zahl1, zahl2)

El problema está aquí. El uso de suma (argumentos) significa que está llamando a una función llamada 'suma', pero no ha hecho de 'suma' una función sino una variable que contiene la suma.

La forma correcta sería:

 ergebnis = sum

Esto funcionaría, pero puede optimizar aún más el código omitiendo variables innecesarias.

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!