Enquiry about question

Hello all , I have Enquiry about this question :

Q} Write a function called longWord that takes an array of Strings as an argument and returns the longest string in the array

I want to know does it mean put something inside the parameters for the function or keep it empty ?

because I solve this question without put inside the parameters any thing , and I make the array outside the function and I just put inside the function a for Loop to get the longest Word , so is that correct ?

Hey @ahmed2009

The text of the question says:

so yes, you need to be passing the array into the function as an argument. Doing it this way makes the function much more robust and reusable.

1 Like

thanks for help Sir , can I know please how to pass the array into function ? does it just type the name of the array inside the function’s brackets ? or what ?

function getLongestString(strings) {
  // do your stuff
}

and then when you call the function:

var fruits = [ 'apple', 'banana', 'pear', 'pineapple' ];
var longest = getLongestString(fruits);
1 Like

If you need the complete solution, it’s here: https://jsfiddle.net/u1Lfh16a/

1 Like

It seems like the question the OP is trying to answer is homework or a test question, so it felt a bit unfair to just give him the solution :stuck_out_tongue_winking_eye:

3 Likes

Thanks a lot for help . :rose:

Thanks for help , but I think this solution is to advanced xD
I solve it in another beginner way xD
anyway thanks a lot man .:hibiscus:

1 Like

I already solve it , but I don’t know a lot about parameters and how to pass an array just …

Does this website has a private message between users?

I thought so, that’s why I gave a link instead of posting code here.
He had a choice :smiley:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.