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

298
Views
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 answers
Answer question

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