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"))