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

87
Vistas
case switch and scope in js

I'm looking for some help. I am not sure my speed, handling, acceleration values in the bottom method arguments are not being affected or using the update values that are being added to within the case-switch. I want speed to take the changes applied in the switch then the updated variable to be pushed in the methods below. I hope I'm making sense. My values always stay at 10

const addAttributes = (_element) => {let selectedElement = _element.layer;

    var speed = 10;
    var handling = 10;
    var acceleration = 10;
  
    switch (_element.layer.name) {
 
      case "1_grill":
        speed = speed + 100;
      
      case "Fiber1":
        handling = handling + 25;
        speed = speed + 25;

      case "yellow_headlights": // asset name without #
        acceleration = acceleration + 35;
    }
   
    attributesList.push({
        trait_type: "Handling",
        Value: handling,})

    attributesList.push({
        trait_type: "Speed",
        Value: speed,})
  
    attributesList.push({
        trait_type: "Acceleration",
        Value: acceleration,})
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Maybe it's because you'e _element.layer.name doesn't match any of the cases never. You should check that.

And you should put a break after each case too.

over 4 years ago · Santiago Trujillo 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