String output missing quotation marks

Hello,

I wrote a function to output either the middle character of a string if an odd number, or the two middle characters if an even number.

I am getting the right answers, but on the tests I have to perform, the output needs to be in this format: ‘t’ , ‘th’, but the outputs I have are t and th (without the quote marks).

I have tested the type of and the outputs are strings. Is this just a matter of concatenation? I have a doubt about this as it would mean wrapping a single quote inside of double quotes which doesn’t look right?

function getMiddle(s) {
  let length = s.length;
  let tempArray = s.split("");
  let remainder = length % 2;
  let i = 0;
  if (remainder == 1) {
    i = Math.floor(length / 2);
    console.log(tempArray[i]);
  } else {
    i = length / 2;
    let resultArray = [tempArray[i - 1], tempArray[i]];
    let arrayToString = resultArray.toString();
    let arrayNoCommas = arrayToString.replace(/,/g, "");
    return arrayNoCommas;
  }
}

I don’t know why it would ask you to wrap strings inside strings. Usually, a string is just written with quotes so it isn’t part of the expected output just how it is written in text requirements.


Is there a reason why you are not using .join()?

I know what you mean, but this was the error message:

Tests
Log
t
expected undefined to equal ‘t’

I think I tried join and it didn’t work (maybe I was doing something wrong).

It is saying it is undefined.

But you are not handling both cases yet so maybe it is for the odd numbers of letters. You are only console logging in the first if statement.

1 Like

that was it. I forgot to change that CL. Thanks a lot