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

101
Views
LocalStorage drag previous saved array

I'm coding a currency converter that save every conversion that the user make and displayed. When i make the first conversion is fine. When i make the second it show the first one and the second, instead of only the second, like a to do list. Also i tried to use a constructor but i dont think that is the problem. If anyone can give me any help, that would be awesome!. Thx.

function calculo(){
    resultado=(cantidad/monedaVal1)*monedaVal2;
    $('#res').html('Obteniendo conversion...');
    $('#res').fadeOut(500)
            .fadeIn(500)
            .fadeOut(500)
            .fadeIn(500,function(){
                
                $('#res').html(cantidad+' '+monedaText1+' = '+resultado.toFixed(2)+' '+monedaText2);
            });
    almacen();
}

class conversion {
    constructor(monto, origen, destino, final) {
        this.monto = monto;
        this.origen = origen;
        this.destino = destino;
        this.final = final;
    }
}

function almacen(){
    cambios.push(new conversion(cantidad,monedaText1,monedaText2,resultado));
    guardarCambio(cambios);
    listarCambio(cambios);
}

function guardarCambio(cambios) {
    let cambio = cargarCambio();
    cambio.push(cambios);
    localStorage.setItem('test', JSON.stringify(cambios));
}

function cargarCambio() {
    if (localStorage.getItem('test')) {
        return JSON.parse(localStorage.getItem('test'));
    }

    return [];
}

function listarCambio(cambios){
    $.each(cambios, function (i) { 
        $('#conversiones').append('<tr><td>'+cambios[i].monto+'</td><td>'+cambios[i].origen+'</td><td>'+cambios[i].destino+'</td><td>'+cambios[i].final+'</td></tr>'); 
    })
}

enter image description here

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