Hi, I am on the ‘Mysterious Organism’ challenge project. For step 4 I have written the code below in order to mutate a random letter in the DNA sequence. My thinking behind this was that if I create new variables with the potential letter replacements and then run through them to replace a randomly selected part of the 15 character array then that would work but I am receiving a syntax error and I can’t see why. The error is suggesting a ) is out of place. Please see code below and feel free to make any comments/suggestions.
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
}
//Factory function for organism
const pAequorFactory = (number , array) => {
return obj = {
specinum: number,
dna: array,
mutate () {
let ifA = ['T' , 'C' , 'G'];
let ifT = ['A' , 'C' , 'G'];
let ifC = ['A' , 'T' , 'G'];
let ifG = ['A' , 'T' , 'C'];
if (this.array[Math.floor(Math.random() * 15)] === 'A'){
return ifA[Math.floor(Math.random() * 4)];
}
if (this.array[Math.floor(Math.random() * 15)] === 'T'){
return ifT[Math.floor(Math.random() * 4)];
}
if (this.array[Math.floor(Math.random() * 15)] === 'C'){
return ifC[Math.floor(Math.random() * 4)];
}
if (this.array[Math.floor(Math.random() * 15)] === 'G'){
return ifG[Math.floor(Math.random() * 4)];
}
else {
return 'Invalid number';
}
}
};