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

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

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