Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
How do I fix my javascript Celsius converter?

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>

How do I make it so that the temperature actually appears and have the "The temperature in Celcius is + convertTemp()" line actually appear when I run the code.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Try this...

You have to just add a Click Event listener to the button

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>

And code without Event Listener (The shortest possible code i can make)

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>

And tell me if its ok for you...

about 4 years ago · Juan Pablo Isaza Denunciar

0

getInputValue() should call convertTemp(), and then assign the result to innerHTML.

You need to use .value to get the input value.

In the formula, you have to put parentheses around inputNumber - 32 to override the default operator precedence.

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 Denunciar

0

Solution without event listener:

<!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>

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda