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

167
Visualizações
javascript convert dollars to egyptian pound

I have this form when the user put a number in dollar and i want to convert this number to egyptian pound

I want to use javascript to do that

let dollarInput = document.querySelector("[name='dollar']");
let result = document.querySelector(".result");


dollarInput.addEventListener("input", () =>{
  if(dollarInput.value !== "" && dollarInput > 0){
     let eG = dollarInput.value * 15.6;
     result.textContent =`{${dollarInput.value}} USD Dollar = {${eG.toFixed(2)}} Egyptian Pound`;
  } 
});
<form action="">
  <input type="number" name="dollar" placeholder="USD Dollar" />
  <div class="result">{0} USD Dollar = {0} Egyptian Pound</div>
</form>

I'm using addEventListener when i put a number to make a change in the div i want to print the value in dollar than en egyptian pound

but my code it's not working can anybody help me to know why and how should i do it

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should be checking whether the value of the input is greater than 0, not the input element itself.

let dollarInput = document.querySelector("[name='dollar']");
let result = document.querySelector(".result");


dollarInput.addEventListener("input", () =>{
  if(dollarInput.value !== "" && dollarInput.value > 0){
     let eG = dollarInput.value * 15.6;
     result.textContent =`{${dollarInput.value}} USD Dollar = {${eG.toFixed(2)}} Egyptian Pound`;
  } 
});
<form action="">
  <input type="number" name="dollar" placeholder="USD Dollar" />
  <div class="result">{0} USD Dollar = {0} Egyptian Pound</div>
</form>

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