Mysterious Organism

Hey, so I’ve been stuck on the Mysterious Organism project because I can’t get this one segement of code to work properly. I’ve done everything else in the project, and I’ve actually moved on to more advanced topics (which I excel at), and this project is still nagging at the back of my mind.

I was hoping someone would be able to help me out. It’s within the compareDNA() method.

Essentially my error is that it is not counting the sameBase variable correctly, and I’m not sure why. I’ve used this same style of code on another project, and the counter worked perfectly fine, so idk why this won’t work for me.

let sameBase = 0;
		this.dna.forEach(firstSubjectBase => {
				pAequorMutation.dna.forEach(secondSubjectBase => {
					if(firstSubjectBase === secondSubjectBase) this.sameBase++;
				});
			});

Misuse of this in this.sameBase. At least from what can be inferred from the context you posted. Not sure exactly what this is as can’t see, so hard to explain what it will be. But this isn’t set when entering an execution context.

You are comparing each element firstSubjectBase with every element of secondSubjectBase. You are only supposed to compare elements in the same position. For example, you need to compare firstSubjectBase[0] with secondSubjectBase[0] .