Ok, this starts to piss me off! The code runs perfectly but I get the message the output is not correct!


#1
function lightRow(row)
{
  var text;
  text+="[";
  for(var i = 0; i < countColumns(); i++)
  {
    text+='\"';
    text+=GRID[row-1][i];
    text+="\"";
    text+=", ";
  }

  text+="]";
  return text;
}

This is the code, go into a compliler and try it, I am tired of this formating issues because you are not capable to specify exactly the why you want it, I don’t know if I have to output a string with the valuse only, or a string with " and , and [ and so on. The output is exactly as asked: ["", “”, “v”, “”, “~”, “”, “”, “”, “”, “”]


#2

Hello SKREFI,

The return needs to be an Array, not a String.


#3

Hey SKREFI!

In programming, we define values using two different things, it’s value, and it’s type.

For example, a variable may have a value of 1, but also has a type of “integer” (meaning number).
If we were to change our value slightly, to say “1”, our value would be very similar, but our type would be much different (in this case, a string).

Your problem here is that you are returning a string representation of what the value that is expected from this function. Think of it this way: you’re expecting your brother to give you a chocolate bar for your birthday. but instead of giving you that chocolate bar, he gives you a piece of paper with the words “this is a chocolate bar” on it.

This is essentially what is happening here.

Your method is doing significantly more than it should be :). It is possible to accomplish everything asked by this challenge with a single line of code.

Good luck!


#4

Ok, I undestand without analogy :smiley: Thanks. But they DON’T SPECIFY THIS!!!


#5

OK, this is the function now, what is wrong with it know because it is still not working!

function lightRow(row)
{
  var text;
  for(var i = 0; i < countColumns(); i++)
  {
    text+=GRID[row-1][i];
  }
  return text;
}

#6

OK, this is the function now, what is wrong with it know because it is still not working!

function lightRow(row)
{
  var text;
  for(var i = 0; i < countColumns(); i++)
  {
    text+=GRID[row-1][i];
  }
  return text;
}

#7

Try simpling it down. You have way too much code.
Try this:
function lightRow(rowNumber) {
return GRID[rowNumber - 1]
}


#8

In relation to your proposed solution, it looks like youre returning a string still. I would look at changing:

var text;

To:

var text = []

This will allow you to return an array rather than a string. You’ll need to look at how to push values to the array.

Alternatively, you could look at returning the whole row (which is an object in the array GRID) by using a variable as a parameter which is passed into the index of GRID within the return statement. Example: GRID[variable]


#9

Just to complement what others have said, I think it’s helpful to see what your code is actually doing. Have a look at this pastebin: https://jsbin.com/dusegawesi/1/edit?js,console

Your function is still returning a string when the problem expects an array as the return type.


#10

This is a fair point, and would definitely be confusing for anyone who isn’t very deep into their programming learning. But now you know forever :slight_smile:


#11

Wow, I have no words seriously, that’s new to me, I have never seen returning a row. I acutally thought it is not possible… I am experienced with C++ only