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

222
Views
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
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!