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

296
Vistas
Why is my code not printing the final result? It should print underneath a button, however nothing is printed

It's my first time coding with Javascript, and I am not sure how to proceed with fixing this code. I have tried basic stuff like checking variables are named correctly. I am unsure with what steps to take to fix this code.

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Convert Fahrenheit to Centigrade</title>
</head>

<body>
    <h1>Convert Fahrenheit to Centigrade</h1>
    <p>Enter degrees in Fahrenheit</p>
    <input type="number" id="Fahrenheit">   
    <p>Degrees in Centigrade</p>
    <input type="number" id="Centigrade">
    <br /><br />
    <button onclick="doCalculation()">Calculate Centigrade from Fahrenheit</button>
    <p id="displayResult"></p>

    
    <script>
        
        var fahrenheit;
        //var centigrade;
        var convertedResult;
        
        
        function calculateTemperature(fahrenheit) 
        { 
            var temperature = (fahrenheit - "32") * 5 / 9; 
            return temperature;
            }

        
        function doCalculation(){
            fahrenheit = document.getElementById("Fahrenheit").value;
            //centigrade = document.getElementById("Centrigrade").value;
            convertedResult = calculateTemperature(fahrenheit)
            document.getElementById("displayResult").innerHTML+= fahrenheit + "in Centigrade is" + temperature;
            }

    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The variable temperature which you are using within the value which is getting printed is not defined. If you check the browser, console, you will be able to identify that error.

The value of the result is stored in the convertedResult variable. That variable should be used within the value which is getting printed instead of temperature

function doCalculation(){
    fahrenheit = document.getElementById("Fahrenheit").value;
    //centigrade = document.getElementById("Centrigrade").value;
    convertedResult = calculateTemperature(fahrenheit)
    document.getElementById("displayResult").innerHTML = fahrenheit + "in Centigrade is" + convertedResult;
}
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