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

225
Vistas
I am trying to use a if statement to determine if the roman numerals is 4, 9, 40, 90, 400, 900 but I am getting undefined

I am getting undefined when I try to run my code, I am not sure why it is not triggering the first condition, does anyone know what I am doing wrong. At this point I know there is a better solution to solve this problem, but I would like to know what I am doing wrong in this particular instance.

var romanToInt = function(s) {
  let romanNumerals = {I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000}
  let integer = 0
  let sToIndex = s.split("")
  
  for (let i = 0; i <= sToIndex.length; i++ ){
      for (let j = 0; j <= romanNumerals.length -1; j++){
          if (sToIndex[i] === "I" && (sToIndex[i + 1] === "V" || "X")){
             integer = Object.values(romanNumerals)[j + 1] - 1
             console.log(integer) 
           }
            else if (Object.key(sToIndex)[i] === "X" & Object.key(sToIndex)[i + 1] === "C"|| "L"){
                integer = Object.values(romanNumerals)[j + 1] - 10
                return integer 
            }else if (Object.key(sToIndex)[i] === "C" & Object.key(sToIndex)[i + 1] === "D" || "M"){
              integer = Object.values(romanNumerals)[j + 1] - 10
              return integer
            }else {
              integer = Object.values(romanNumerals)[j] + Object.values(romanNumerals)[j+1]
              return integer 
            }
          }
        }

}

console.log(romanToInt("IV"))
about 4 years ago · Juan Pablo Isaza
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