-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquoteAutomation.js
More file actions
34 lines (30 loc) · 1.21 KB
/
Copy pathquoteAutomation.js
File metadata and controls
34 lines (30 loc) · 1.21 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
32
33
34
//Works on Edge, but not Chrome (unless file is web-hosted)
$('body').ready(function () {
//Date information:
var d = new Date();
var startingMonth = 4; //The month that the first quote was used
var currentYear = d.getFullYear() - 2021; //The year since 2021
var currentMonth = (currentYear * 12) + d.getMonth() + 1; //The months since April 2021
var monthsSinceIndex = function(start, current)
{
var numMonths = current - start;
return numMonths;
}
console.log("months since January 2021: " + monthsSince(startingMonth, currentMonth));
//File information:
var file = 'quotes.txt'; //imports quotes.txt
console.log("imported file");
var lineNumber = monthsSinceIndex(startingMonth, currentMonth); //index of monthly quote (assigned for efficiency)
/**
* Precondition: the file requested exists and the month is past April 2021
**/
var readLine = function(file, line)
{
$.get(file, function(data) {
var items = data.split('\n');
$('#QOTM').text("Quote of the Month: " + items[line]);
});
}
//Output:
readLine(file, lineNumber);
});