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

207
Views
¿Cómo arreglo mi convertidor Celsius de javascript?

 document.getElementById("result").innerHTML = "The temperature in Celcius is " + convertTemp() + "!" function getInputValue() { var inputNumber = document.getElementById("numberEnter") } function convertTemp() { document.getElementById("result") return (5 / 9) * inputNumber - 32 }
 <!DOCTYPE html> <html> <head> </head> <body> <input type="text" placeholder="What is the temperature..." id="numberEnter"> <button type="button" onclick="getInputValue();">Click to get temperature!</button> <p id="result"></p> </body> </html>

¿Cómo hago para que la temperatura realmente aparezca y tenga la línea "La temperatura en Celcius es + convertTemp ()" cuando ejecuto el código?

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

0

Prueba esto...

Solo tiene que agregar un detector de eventos de clic al botón

 document.getElementById("result").innerHTML = `The temperature in Celsius is ${convertTemp(document.getElementById("numberEnter").value)} !` function convertTemp(inputTemp) { return (5/9)*(inputTemp-32) } document.getElementById("button").addEventListener('click', function () { document.getElementById("result").innerHTML = `The temperature in Celsius is ${convertTemp(document.getElementById("numberEnter").value)} !` })
 Fahrenheit: <input type="text" placeholder="What is the temperature..." id="numberEnter" value=0> <button type="button" id="button">Click to get temperature!</button> <p id="result"></p>

Y código sin Event Listener (El código más corto posible que puedo hacer)

 function convertTemp() { document.getElementById("result").innerHTML = `The temperature in Celsius is ${(5/9)*(document.getElementById("numberEnter").value-32)} °C!` }
 °F: <input type="text" placeholder="What is the temperature..." id="numberEnter" value=0><button type="button" id="button" onclick="convertTemp()">Click to get temperature!</button> <p id="result"></p>

Y dime si te parece bien...

about 4 years ago · Juan Pablo Isaza Report

0

getInputValue() debe llamar a convertTemp() y luego asignar el resultado a innerHTML .

Debe usar .value para obtener el valor de entrada.

En la fórmula, debe colocar paréntesis alrededor inputNumber - 32 para anular la precedencia predeterminada del operador.

 function getInputValue() { var inputNumber = parseFloat(document.getElementById("numberEnter").value); document.getElementById("result").innerHTML = "The temperature in Celcius is " + convertTemp(inputNumber) + "!" } function convertTemp(inputNumber) { return (5 / 9) * (inputNumber - 32) }
 <!DOCTYPE html> <html> <head> </head> <body> <input type="text" placeholder="What is the temperature..." id="numberEnter"> <button type="button" onclick="getInputValue();">Click to get temperature!</button> <p id="result"></p> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

Solución sin detector de eventos:

 <!DOCTYPE html> <html> <head> </head> <body> <input type="text" placeholder="What is the temperature..." id="numberEnter"> <button type="button" onclick="getInputValue();">Click to get temperature!</button> <p id="result"></p> <script> function getInputValue(){ var inputNumber = document.getElementById("numberEnter").value; document.getElementById("result").innerHTML = "The temperature in Celcius is " + convertTemp(inputNumber) + "!" } function convertTemp(f){ document.getElementById ("result") return (5/9) * (f - 32) } </script> </body> </html>

Ejemplo: https://tortoiseshell-silken-stranger.glitch.me/f2c.html

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!