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

73
Visualizações
how to fix my Metric/Imperial unit conversion project in Javascript

i am trying to build a solo project in javascript. I am having trouble to display a function when an number input is submitted.

this is my HTML code

<header>
    <h1>Metric/Imperial unit conversion</h1>
    <form>
      <input type="number" name="input" id="input1">
    <input type="submit" onclick="meterFeet()">
    </form>
</header>
    <main>
      <h3>Length (Meter/Feet)</h3>
      <p class="p-l" id="p-l1" "></p>
      
    </main>

and this is my javascript code

let miucn = document.getElementById("input1");

function meterFeet() {
  document.getElementById("p-l1").textContent =
    miucn +
    " meters = " +
    (miucn * 3.281).toFixed(3) +
    " feet | " +
    miucn +
    " feet =" +
    (miucn / 3.281).toFixed(3) +
    " meters";
} 
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I made some small fixes in your code.

  1. change input type from submit to button
  2. put (document.getElementById("input1").value) inside the function
  3. parseInt() the input value

function meterFeet() {
  let miucn = parseInt(document.getElementById("input1").value);
  
  document.getElementById("p-l1").textContent =
    miucn +
    " meters = " +
    (miucn * 3.281).toFixed(3) +
    " feet | " +
    miucn +
    " feet =" +
    (miucn / 3.281).toFixed(3) +
    " meters";
  return false;
} 
<header>
    <h1>Metric/Imperial unit conversion</h1>
    <form>
      <input type="number" name="input" id="input1">
      <input type="button" onclick="meterFeet()" value="Submit">
    </form>
    </header>
    <main>
      <h3>Length (Meter/Feet)</h3>
      <p class="p-l" id="p-l1" "></p>
      
    </main>

about 4 years ago · Santiago Gelvez 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