Mysterious Organism Challenge Project (JavaScript)

Congratulations on completing your project!

Compare your project to our solution code and share your project below! Your solution might not look exactly like ours, and that’s okay! The most important thing right now is to get your code working as it should (you can always refactor more later). There are multiple ways to complete these projects and you should exercise your creative abilities in doing so.

This is a safe space for you to ask questions about any sample solution code and share your work with others! Simply reply to this thread to get the conversation started. Feedback is a vital component in getting better with coding and all ability levels are welcome here, so don’t be shy!

About community guidelines: This is a supportive and kind community of people learning and developing their skills. All comments here are expected to keep to our community guidelines

How do I share my own solutions?

  • If you completed the project off-platform, you can upload your project to your own GitHub and share the public link on the relevant project topic.
  • If you completed the project in the Codecademy learning environment, use the share code link at the bottom of your code editor to create a gist, and then share that link here.

Do I really need to get set up on GitHub?
Yes! Both of these sharing methods require you to get set up on GitHub, and trust us, it’s worth your time. Here’s why:

  1. Once you have your project in GitHub, you’ll be able to share proof of your work with potential employers, and link out to it on your CV.
  2. It’s a great opportunity to get your feet wet using a development tool that tech workers use on the job, every day.

Not sure how to get started? We’ve got you covered - read this article for the easiest way to get set up on GitHub.

Best practices for asking questions about the sample solution

  • Be specific! Reference exact line numbers and syntax so others are able to identify the area of the code you have questions about.

Hi anna, thanks for the solution.

I noticed the solution for Question 4: .mutate was as such.

      this.dna[randIndex] = newBase;

After experimenting, I realized this doesn’t seem to work. this.dna remains unchanged, and doesn’t mutate at the specified index.

How do I replace a character at a particular index in JavaScript?

I’m not sure whether I understood the problem correctly too.

Hey Mr. WebJumper, I had a similar symptom to some things in my code. In the end I realized that for some reason if you’re checking its functionality with console.log() within the method, it seems to log things after the changes have been made. so I’d have a console.log(this.dna) before the .splice() and then an exact same one afterwards. When in reality, the code was working fine and was indeed changing the bases properly.

NOTE: My blunder was also doing Math.random instead of Math.random() making randIndex = NaN

Try doing this on your browser console (open tab > right click anywhere > Inspect Element > change to Console), enter the object with its methods, create animal1, log its DNA strand, mutate it, then log its DNA again. I’ll leave my working code here if you want to compare!

Short version: the code you mentioned should work if the rest is done properly.

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

// Returns a random single strand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = [];
  for (let i = 0; i < 15; i++) {
  return newStrand;

const pAequorFactory = (num, bases) => {
  return {
    specimenNum: num,
    dna: bases,
    mutate() {
      // random Loc on DNA
      let i = Math.floor(Math.random() * this.dna.length);

      // target base's letter
      let oldBase = this.dna[i];

      // Swapping out (mutating) base on DNA
      let altBases = ['A', 'T', 'C', 'G'];
      altBases.splice(altBases.indexOf(oldBase), 1); // find and remove target base
      let mutatedBase = altBases[Math.floor(Math.random() * 3)]; // take one of 3 altBases
    //   console.log(`Changed ${oldBase} to ${mutatedBase} on number ${i}`);
      return this.dna.splice(i, 1, mutatedBase);   
    compareDNA(otherPAqeour) {
      let count = 0;
      for (let i = 0; i < this.dna.length; i++) {
        if (this.dna[i] == otherPAqeour.dna[i]) {
          count += 1;
      // console.log(`Specimen #${this.specimenNum} has ${count * 100/this.dna.length}% DNA bases in common with #${otherPAqeour.specimenNum}.`)
    willLikelySurvive() {
      const cAndG = this.dna.filter(letter => letter === 'C' || letter === 'G');

      if (cAndG.length/this.dna.length > 0.6) {
        return true;
      } else {
        return false;

  // 30 instances
let sample = [];
let i = 0;
while (sample.length < 30) {
  let temp = pAequorFactory(i, mockUpStrand());
  if (temp.willLikelySurvive() == true) {
    i += 1

Hey guys! So i have been sitting and staring at t his portion of the problem now for a while. I have tried both the provided solution code and other forum members’ solutions to no avail. This is the code that I have come up with to try and solve the mutation part of the problem but keep getting the same strand of DNA printed to console in both cases. It’s as if the mutation method never runs.

I have tried to log the index created under i as well as the randomBase that i selects but sometimes I get differing values. I.e. my index value will be 4 but the randomBase that is logged to the console is a base in the DNA that does not equate to the element at said index.

If anyone can offer assistance I would love you forever and ever. My biggest hurdle in this program is having assistance when I get stumped for an hour plus.

Zach V

I’m also having the same problem, I’ve got the code, but it’s also printing out function: function name, instead of working. I feel like there is very simple solution to this that I’m missing, if anyone would point this, I’d be very grateful.

Never mind, found it. When you call a function inside an object, you have to be more specific and specify the method. function(param1, param2).method