Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
Incrementing score on React Rap Quiz Not working

I'm using the setState to increment the score of a quiz I made. I'm using the callback method so I don't mutate the data but it's only showing me a score of 2. I don't get what i'm doing wrong here.. I'm calling the calculateScore function whenever the form is submitted onSubmit={this.calculateScore}.


        if(this.state.question1 === '1996') {
            this.setState((curr)=>{
                return {score: curr.score++}
            })
        }

        if(this.state.question2 === 'NWA') {
            this.setState((curr)=>{
                return {score: curr.score++}
            })
        }

        if(this.state.question3 === 'bad-boy') {
            this.setState((curr)=>{
                return {score: curr.score++}
            })
        }

        if(this.state.question4 === 'big-l') {
            this.setState((curr)=>{
                return {score: curr.score++}
            })
        }

        if(this.state.question5 === 'snoop-dogg') {
            this.setState((curr)=>{
                return {score: curr.score++}
            })
        }

        console.log(this.state);
        console.log('calculating')
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are using the postFix operator value++ as opposed to prefix ++value. Try with prefix operator and it should work fine,

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Increment

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda