var quotes = ['blah1', 'blah2', 'blah4'];
var calc = Math.floor(Math.random()*quotes.length);
var quote = quotes[calc];
What is quotes[calc]
? What is it called and how it works?
var quotes = ['blah1', 'blah2', 'blah4'];
var calc = Math.floor(Math.random()*quotes.length);
var quote = quotes[calc];
What is quotes[calc]
? What is it called and how it works?
The quotes variable contains an array of 3 string elements. Arrays have indexes starting at 0 and increment by 1 for each element in the array. You can reference a specific element of an array using its index in the following syntax:
quotes[0] // refers to the first string element which is 'blah1'
quotes[1] // refers to the second string element which is 'blah2'
quotes[2] // refers to the third string element which is 'blah3'
I suggested starting the following challenge of the FCC curriculum on arrays and working through several of the array related challenges to gain a greater understanding of how arrays work and can be used.