This is my first question here ... How to return this value that is in the console.log (convert) to the input with #fahrenheit, which I have already stored in a variable with the same name? Already tried:
document.querySelector('#fahrenheit').innerText = converte
But it did not work. also textContent.
document.querySelector('#temp-form').addEventListener('submit', calcular);
//função calculadora
function calcular(e){
// pegar o valor em Celsius
const celsius = document.querySelector('#celsius');
// calculos
const principal = parseFloat(celsius.value);
const converte = parseFloat((9 * principal + 160) / 5);
console.log(converte);
e.preventDefault();
}
In addition, parseFloat does not seem to work because the field rejects decimal values. Why?
Follow the HTML:
<!doctype html>
<html lang="pt-br">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
<title>Conversor de Temperatura</title>
</head>
<body class="bg-info">
<div class="container mt-5">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card card-body text-center mt-5">
<h1 class="heading display-5 pb-3">Conversor de Temperatura</h1>
<form id="temp-form">
<div class="form-group">
<div class="input-group">
<span class="input-group-text">ºC</span>
<input type="number" class="form-control" id="celsius" placeholder="Temperatura em Celsius">
</div>
</div>
<div class="form-group">
<input type="submit" value="Calcular" class="btn btn-danger btn-block">
</div>
</form>
<!-- RESULTS -->
<div id="results" class="pt-4"><h5>Resultados</h5></div>
<div class="form-group">
<div class="input-group">
<span class="input-group-text">Fahrenheit</span>
<input type="number" class="form-control" id="fahrenheit" disabled>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="js/app.js"></script>
</body>
</html>