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

162
Visualizações
How to take an HTML integer input and work with it in JavaScript

I have been trying to make a calculator website as practice to learn HTML, CSS and JS. However, I need help with fetching an integer value from HTML and working with it in javascript. here is my code

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="3D.css">
    <title>3D Shapes Calculator</title>
</head>
<body>
<div class="spearesSection">
        <div class="spearesSectionHeading" id="sectionSpearesHeading">
            <p class="spearesSectionText">Calculate the Volume of a Speare!</p>
        </div>
        <div class="workAreaSpeares">
            <img class="spearesPicture" src="../Images/Speare.jpg" alt="Error, Page cannot be loaded">
            <p class="textSpearesRadius">Radius:</p>
            <input type="number" class="inputRadiusSpeare" id="radiusInput">
            
            <button class="buttonExecuteSpeares" id="buttonExecuteSpeares" onclick="spearesSolve()">Solve!</button>
            <p class="answerSpeare"> Answer =</p>
            <div class="outputAreaSpeare"></div>
            <p class=answerSpearePi>In Terms of Pi =</p>
            <div class="outputAreaSpearePi"><p class="piSpeare">π</p></div>
        </div>
    </div>
</body>
<script src="3D.js"></script>
</html>

JS:

let radiusInput = document.getElementById("radiusInput").Value;
let radiusOutput;

function spearesSolve() {
    radiusOutput = (radiusInput ** 3) * 3.14159265359 * (4/3);
   console.log(radiusOutput)
}

PS: I didn't include my to keep it neat

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

You need to get the input value in the click handler, also value should be lowercase.

let radiusInput = document.getElementById("radiusInput");
let radiusOutput;

function spearesSolve() {
    radiusOutput = (radiusInput.value ** 3) * 3.14159265359 * (4/3);
   console.log(radiusOutput)
}
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