Javascrip syntax part ||/mysterious organism project

https://gist.github.com/0da9ccfd07403bf0eae0ffa37aab18aa
please can someone help me to resolve this problem inside the function pAequor which’s name “mutate” so when i try to run the code in the console it execute this error : onsole.log(pAequorFactor.mutate());
^

TypeError: pAequorFactor.mutate is not a function
and this is my code function : `// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = [‘A’, ‘T’, ‘C’, ‘G’]
return dnaBases[Math.floor(Math.random() * 4)]
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand =
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactor = (num, basesArray) => {
return {
SpecimenNum:num,
dna:basesArray,
mutate () {
let currentBase = returnRandBase();
let generatedBase;
let newStrand = ;
if (currentBase === “A”) {
generatedBase = bases.slice(1).Math.floor(Math.random(3))
} else if(currentBase === “T”) {
generatedBase = [‘A’, ‘C’, ‘G’].Math.floor(Math.random(3))
} else {
generatedBase = [‘A’, ‘T’, ‘C’].Math.floor(Math.random(3));
}
for(let i = 0;i < 15; i++) {
this.dna = newStrand.push(generatedBase);

}
return this.dna;

}
}
}
console.log(pAequorFactor.mutate());

`

You’re trying to apply the method .mutate() on an object that doesn’t exist. If pAequorFactor was a factory function, you’d need to create an instance of that object, before you can apply a method on it.

Why don’t you write pAequorFactor as an object initially?

please how to declare an instance i forget it

If your function were a working constructor, you’d create an instance with:
new pAequorFactor(num, basesArray);
But I don’t think that works here. So I’d write pAequorFactor as an object with object literals like this:

const pAequorFactor = {)

Then you wouldn’t need to create an instance and you could apply the method directly on the object.

Thanks a lot my friend for your help but this exercice require an factory function

Can you post a link to the excercise?

sorry this is the link https://www.codecademy.com/paths/full-stack-engineer-career-path/tracks/fscp-javascript-syntax-part-ii/modules/fecp-challenge-project-mysterious-organism/projects/mysterious-organism

pAequorFactor() should return an object that contains the properties specimenNum and dna that correspond to the parameters provided.’
When you call your function, it doesn’t return an object. This would:

const pAequorFactory = (num, arr) =>{
  return{
    specimenNum: num,
    dna: arr
  }
}

Edit: corrected factory function

yes thank you but i try to call the method .mutate() inside that function but the console execute this error : const aequor = new pAequorFactor(1, mockUpStrand);
^

TypeError: pAequorFactor is not a constructor

Can you post that code?

thank you an other time my friend for the spaceiouseness of your chest and this is the code : https://gist.github.com/e5f158fa910d924698288719bf6e7bbd

// Returns a random DNA base
const returnRandBase = () => {
  const dnaBases = ['A', 'T', 'C', 'G']
 return dnaBases[Math.floor(Math.random() * 4)]
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = []
  for (let i = 0; i < 15; i++) {
    newStrand.push(returnRandBase())
  }
  return newStrand
}
const pAequorFactor = (num, basesArray) => {
return obj = {
  SpecimenNum:num,
  dna:basesArray,
  mutate () {
let currentBase = returnRandBase();
let generatedBase;
let newStrand = [];
if (currentBase === "A") {
  generatedBase = bases.slice(1).Math.floor(Math.random(3))
} else if(currentBase === "T") {
generatedBase = ['A', 'C', 'G'].Math.floor(Math.random(3))
} else {
  generatedBase = ['A', 'T', 'C'].Math.floor(Math.random(3));
}

 this.dna =  mockUpStrand(generatedBase);
  

return this.dna;

}
}
}
const aequor = new pAequorFactor(1, mockUpStrand);
console.log(aequor.mutate()) 






// Returns a random DNA base
const returnRandBase = () => {
  const dnaBases = ['A', 'T', 'C', 'G']
 return dnaBases[Math.floor(Math.random() * 4)]
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = []
  for (let i = 0; i < 15; i++) {
    newStrand.push(returnRandBase())
  }
  return newStrand
}
const pAequorFactor = (num, basesArray) => {
return obj = {
  SpecimenNum:num,
  dna:basesArray,
  mutate () {
let currentBase = returnRandBase();
let generatedBase;
let newStrand = [];
if (currentBase === "A") {
  generatedBase = bases.slice(1).Math.floor(Math.random(3))
} else if(currentBase === "T") {
generatedBase = ['A', 'C', 'G'].Math.floor(Math.random(3))
} else {
  generatedBase = ['A', 'T', 'C'].Math.floor(Math.random(3));
}

 this.dna =  mockUpStrand(generatedBase);
  

return this.dna;

}
}
}
const aequor = new pAequorFactor(1, mockUpStrand);
console.log(aequor.mutate()) 






// Returns a random DNA base
const returnRandBase = () => {
  const dnaBases = ['A', 'T', 'C', 'G']
 return dnaBases[Math.floor(Math.random() * 4)]
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = []
  for (let i = 0; i < 15; i++) {
    newStrand.push(returnRandBase())
  }
  return newStrand
}
const pAequorFactor = (num, basesArray) => {
return obj = {
  SpecimenNum:num,
  dna:basesArray,
  mutate () {
let currentBase = returnRandBase();
let generatedBase;
let newStrand = [];
if (currentBase === "A") {
  generatedBase = bases.slice(1).Math.floor(Math.random(3))
} else if(currentBase === "T") {
generatedBase = ['A', 'C', 'G'].Math.floor(Math.random(3))
} else {
  generatedBase = ['A', 'T', 'C'].Math.floor(Math.random(3));
}

 this.dna =  mockUpStrand(generatedBase);
  

return this.dna;

}
}
}
const aequor = new pAequorFactor(1, mockUpStrand);
console.log(aequor.mutate()) 






// Returns a random DNA base
const returnRandBase = () => {
const dnaBases = [‘A’, ‘T’, ‘C’, ‘G’]
return dnaBases[Math.floor(Math.random() * 4)]
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
const newStrand =
for (let i = 0; i < 15; i++) {
newStrand.push(returnRandBase())
}
return newStrand
}
const pAequorFactor = (num, basesArray) => {
return obj = {
SpecimenNum:num,
dna:basesArray,
mutate () {
let currentBase = returnRandBase();
let generatedBase;
let newStrand = ;
if (currentBase === “A”) {
generatedBase = bases.slice(1).Math.floor(Math.random(3))
} else if(currentBase === “T”) {
generatedBase = [‘A’, ‘C’, ‘G’].Math.floor(Math.random(3))
} else {
generatedBase = [‘A’, ‘T’, ‘C’].Math.floor(Math.random(3));
}

this.dna = mockUpStrand(generatedBase);

return this.dna;

}
}
}
const aequor = new pAequorFactor(1, mockUpStrand);
console.log(aequor.mutate())








I’m sorry, I had a syntax error in my example. I think there is still something wrong with the mutate method, so I replaced it with a simple string return.

const pAequorFactor = (num, basesArray) => {
  return {
    SpecimenNum: num,
    dna: basesArray,
    mutate(){
    	return 'mutate';
    }
  }
}
const obj = pAequorFactor(1,['arr']);
console.log(obj.mutate());
1 Like

Thanks for your help my friend i will check the code after, iwill take a break time