Challenge 3 - Can't make it work :(


#1

Here’s my code:
function gridSize(){
var rows = countRows();
var cols = countColumns();
return (" ’ “+rows+” x " +cols+" ’ ");
}
(added spaces for " ’ " so we can see the ’ but i run it without the spaces). I can’t see why this code doesn’t create the good result. Plz help :’(


#2

You don’t need to add " ’ ". Just return (cols +” x " + rows); should work


#3

@shashi i tried without them and it stills doesn’t work :’( . I tried to stock it in a local variable and then return it but it still doesn’t work :’(
code:
function gridSize(){
var rows = countRows();
var cols = countColumns();
var size = “”+rows+" x " +cols;
return size;
}


#4

It might help more to look at how the problem is worded. It wants the function to return things in the format of ‘width x height’. If you look at your grid, would rows correspond to width, or height?


#5

return "'" + countRows().toString() + " x " + countColumns().toString() + "'";

I do it like this but it is not working :confused:


#6

You don’t need the single quotations marks in your code. The single quotations are just to show which string they want you to return.


#7

Ok, removed them, not working…

Tried to return the size, I mean 10 * 10 = 100 and using variables and not using those 2 functions and so on but nothing’s working


#8

try rows.toString and same for Columns it worked for me


#9

when appending to a string you only need to write a single quotation mark …
for example:

var x = ‘hello’;
var y = ‘world’;
var string = x + ‘big’ + y;

i’ll let you guess the output of var: string :slight_smile:


#10

@esgue try this

function gridSize(){
var rows = countRows();
var cols = countColumns();
var size = cols +" x " +rows;
return size;
}


#11

i don’t know why when i wrote it myself it didn’t worked but when i copied your code it worked… but thank youuuuuuuuuuu life saveeeer


#12

shashi’s code solution worked because of the order of the variables in the concatenated size string that you return in your gridSize function. MageDragonfire mentioned above that you need to think about which function corresponds to providing the width of the grid and which one returns the height. That is where the solution becomes clear.


#13

@MageDragonfire and @brianh0001 know what’s going on. :slight_smile: