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

151
Visualizações
Value from Session Storage as a number?

I have two values on my html: "Money" and "Time", and those values come from Session Storage, depending on what the person filled previously in another html page. So lets say the person filled that they need to pay $100 in 2 days.

So the idea would be for the result to be displayed on my HTML like:

  • $50
  • $50

If the number of days increased to 4, for example, the result would be:

  • $25
  • $25
  • $25
  • $25

When i hard code random numbers as the values for "Money" and "Time", the result is exactly what i need, just like the example above. But whenever i try to get the values from Session Storage, the result is always ONE topic of the <li> that i wanted to create, just like the example below:

Money: 100 / Days: 2

  • $50

My code so far:

<p id="money-value"></p>
<p id="time-value"></p>
<div id="payments"></div>
<script>
   const displayMoney = document.getElementById("money-value");
   const storedMoney = parseInt(sessionStorage.getItem("Money"));
   window.addEventListener("load", () => {
       displayMoney.innerHTML =  "Money: " + storedMoney
   });
   
   const displayTime = document.getElementById("time-value");
   const storedTime = parseInt(sessionStorage.getItem("Time"));
   window.addEventListener("load", () => {
       displayTime.innerHTML =  "Time: " + storedTime
   });
   
   var calc = storedMoney / storedTime;
   
   for (let i = 0; i < storedTime; i++) {
      var list = document.createElement("li");
      list.innerText = `${calc}`;
      document.getElementById("payments").appendChild(list);
   }
   
</script>

TL;DR

What i'm really struggling with, is to make the <li> display the payments in the same number of topics as the number of days.

about 4 years ago · Juan Pablo Isaza
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