-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (27 loc) · 1.04 KB
/
index.js
File metadata and controls
31 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Dependencies
const mathLibrary = require('./lib/math');
const quotesLibrary = require('./lib/quotes'); //by default quotes/index.js
//App object - Module scaffolding (building basic sketelon structure)
const app = {};
//configuration
app.config = { //property added
timeBetweenQuotes:1000,
};
//Function that prints a random quotes
app.printOneQuote = function printOneQuote(){
//get all the quotes
const allQuotes = quotesLibrary.allQuotes(); //allQuotes return an array
//get the length of the quotes
const quotesLength = allQuotes.length;
//pick random quotes
const randomNumber = mathLibrary.getRandomNumber(1,quotesLength);
// Get the quote at that position in the array (minus one)
const selectedQuotes = allQuotes[randomNumber-1];
console.log(selectedQuotes);
}
//function that loop indefinitely,calling the printOneQuote()
app.indefiniteLoop = function indefiniteLoop(){
//create the interval, using the config variable defined above
setInterval(app.printOneQuote, app.config.timeBetweenQuotes);
}
app.indefiniteLoop();