0

Hope this question makes sense:

I'm attempting to select a random item from an array saved in a CSV. The assignment is to randomly select 1 line from the song saved in the array and make that line uppercase. However, I'm having a hard time randomly selecting the line.

Here is what I got:

var pickALine = function() 
{
var randomLine = parsed_text[Math.floor(Math.random() * 
parsed_text.length)];
return randomLine;
};
console.log(pickALine());

just trying to print the line for testing

It does print, but the entire array, not just one line.

skuiikidd
  • 1
  • 1
  • Either the problem is mis-represented (there is nowhere in that code where the parsed_text is printed in it's entirety "as an" array) or, quite likely, `parsed_text` is an array of one string instead of an array of lines.. – user2864740 Nov 22 '17 at 22:04
  • Thanks for answering! I thought so too, however later in the program I have a for loop that prints the array one element (line of the song) at a time which works just fine. That couldn't be the case if the array was one string, right? – skuiikidd Nov 22 '17 at 22:06
  • Maybe you've changed the array between those two sections. The code you've posted is the correct way to select a random element of an array, so the problem must be that the array doesn't contain what you expect. – Barmar Nov 22 '17 at 22:28

0 Answers0