Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
Nested Function - this.function in javascript still occur the "is not a function" error

I want to write the two function inside RomanNumerals function

RomanNumerals.toRoman()
RomanNumberals.fromRoman()

which will return the Roman Number or decode the Roman Numerals. The code is the following as below

function RomanNumerals(x){
this.toRoman = function(x){
        var  roman = {M:1000,CM:900, D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1 }
  
  var ans = '';
  while(number>0){
      for(a in roman){ 
          console.log(a,ans)
          if(roman[a]<=number)
          { ans += a; 
            number-=roman[a]; 
            console.log(a,ans,number)
            break;}
              
      }
  }
  return ans;
  }
  
this.fromRoman = function(x){
        let sum = 0, a;
        const romanNo = { I : 1, V : 5, X : 10, L : 50, C: 100, D : 500, M : 1000}
        const numbers = roman.split('')
        for(let i = 0; i < numbers.length; i++ ){
            if (romanNo[numbers[i]] < romanNo[numbers[i+1]])
            {
                sum += romanNo[numbers[i+1]] - romanNo[numbers[i]]
                i++;
            }
            else 
            {
                 sum+=romanNo[numbers[i]]
            }
        }
        return sum

    }

}

but it is still occouring the following error

TypeError: RomanNumerals.toRoman is not a function

I have looked up a few references similar to this post and followed the following link JavaScript Nested function the code syntax mentioned at the below

function Fizz(qux)
{
  this.buzz = function(){
    console.log( qux );
  };
}

still occur the following error as well

TypeError: Fizz.buzz is not a function

What am I missing here to solve this issue?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda