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

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