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

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

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 Report

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 Report

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