Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
How to print an initial value using document write

My code calculates correctly except I can not get the initial temperature to display, in this case "45.9", to print.

Current output:

function FtoC(Fahrenheit) { return (Fahrenheit - 32) * 5 / 9; } F = 7.722222222222222 C

Where FtoC(Fahrenheit) { return (Fahrenheit - 32) * 5 / 9; } is to equal the number 45.9.

Desired output:

45.9 F = 7.722222222222222 C

Code:

<script>
function FtoC(Fahrenheit)
{
return (Fahrenheit - 32) * 5 / 9;
}

var theFahrenheit = FtoC(45.9);
document.write("<br>");
document.write(FtoC + " F = " + theFahrenheit + " C");
</script>
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

you can try returning an array from your function FtoC like below:

function FtoC(Fahrenheit)
{
return [Fahrenheit, (Fahrenheit - 32) * 5 / 9];
}

var theFahrenheit = FtoC(45.9);

document.write("<br>");

document.write(theFahrenheit[0] + " F = " + theFahrenheit[1] + " C");

or Else if you already know the input, you can directly use it instead of returning it in an array.

document.write(45.9 + " F = " + theFahrenheit[1] + " C");

about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

<script>
  function FtoC(Fahrenheit) {
    return (Fahrenheit - 32) * 5 / 9;
  }

  let temperature = 45.9;
  var theFahrenheit = FtoC(temperature);
  document.write("<br>");
  document.write(temperature + " F = " + theFahrenheit + " C");
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

On this line:

document.write(FtoC + " F = " + theFahrenheit + " C");

You're writing out FtoC, which is your function, not the temperature. Try introducing a new variable to hold the initial temperature, and write that out to the document instead.

<script>
    function FtoC(Fahrenheit)
    {
        return (Fahrenheit - 32) * 5 / 9;
    }

    var theTemp = 45.9
    var theFahrenheit = FtoC(theTemp);
    document.write("<br>");
    document.write(theTemp + " F = " + theFahrenheit + " C");
</script>

I also noticed in that line that you're writing theFahrenheit + " C" which seems backwards. Since the variable theFahrenheit is holding the temperature after conversion, it should be named something else.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda