When you say return do you mean print to screen? In the context of functions, return has special meaning and that meaning is unrelated to making things show up on screen.
If you printed something and the printed text was [Function: mutate]
Then what you were printing was probably the function itself? That’s of course something you’d already know because you wrote code to print it. But is printing a function a meaningful thing to do? What would one usually do with a function? Call it, right? That’s pretty much the only operation you would do with a function.
> f = () => 5
> console.log(f) // printing f: kind of pointless
> console.log(f()) // printing the result of calling f, maybe f returns something interesting that can be printed
Ok, so I called the function correctly, and it still returns [Function: mutate]. But the return statement I added also returns the DNA base that was randomly generated without changing and returning the rest of the DNA strand:
Figure out what it’s supposed to do, and then use that.
You need to be a whole lot more deliberate about what you write.
You should probably start with a minimal piece of code where you know what everything does, then consider what you need to be adding on to that to get closer to your goal. Make a small change, test whether the change had the desired effect. You now have a new situation, what is the next change to make? Again, test it.
If you need some kind of action that you don’t know how to use, then you’ll have to stop and go learn it separately. Maybe there’s something you need to be reading or maybe you just need a separate file where you test it out with nothing else in it.
If you write a whole lot at once without testing anything inbetween it’s because you already have good control of it all and anything that could possibly go wrong is something you’re willing to deal with.
Dealing with multiple things that you don’t know what they do won’t work. How will you reason about one thing when you don’t know how the things around it work either?
You might for example want to start with an object that has an integer, and a method that increases the integer.
Separately from that you might want to figure out the more complicated operations in as much isolation from anything else as possible.
Are you able to generate random numbers? Are you able to select random elements? Can you successfully test whether two things are equal?
When you have some control over the smaller pieces you can start adding one of them into the other.
Looking at the things in your code, there’s nothing in it suggesting that your code should be aware of “lines” or text, or screens.
So if the format of your output isn’t what you expected, that’s not a problem with the method because that’s not something your method is responsible for, is it?
So what is it responsible for? For testing you should probably be printing out the object, then call your method, and then print out the object again. Did it change in the way that it should? If the method is supposed to have a return value (not printing) then you would want to look at that as well. Quite often though, you would either create a new value and return it, or modify it and have no return value. Both changing something and returning something is a little bit weird, as if it can’t quite figure out what its purpose is, it should do one thing.
myObj = new Something()
print initial state: myObj
result = myObj.dothething()
print return value: result
print new state: myObj