-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
60 lines (51 loc) · 2.07 KB
/
script.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//const fetch = require('node-fetch');
/*const {getBibleVerse} = require('./sefaria.js');*/
import {getBibleVerse} from './sefaria.js';
const getQuote = async () => {
let inspiringQuote = "";
let inspiringAuthor = "";
let bibleQuote = "";
let asciiArt = "";
const response = await fetch('https://type.fit/api/quotes');
if (response.ok) {
const jsonResponse = await response.json();
console.log(jsonResponse);
const randomQuoteIndex = Math.floor(Math.random() * jsonResponse.length);
inspiringQuote = jsonResponse[randomQuoteIndex].text;
inspiringAuthor = jsonResponse[randomQuoteIndex].author;
console.log(inspiringAuthor);
}
bibleQuote = await getBibleVerse();
console.log('This is the bibleVerse' + " " + bibleQuote[2]);
const plusQuote = bibleQuote[2].split(" ").join(' ');
console.log(plusQuote);
const asciiResponse = await fetch('/asciiart', {method: 'POST', body: plusQuote, headers: {'Content-type': 'text/plain'} });
if (asciiResponse.ok) {
const jsonAscii = await asciiResponse.text();
console.log(jsonAscii);
asciiArt = jsonAscii;
} else {
asciiArt = 'Unavailable';
}
return [inspiringQuote, bibleQuote, asciiArt, inspiringAuthor];
}
const makeQuote = async () => {
const messageDiv = document.getElementById('messageDiv');
const p = document.createElement('p');
p.setAttribute('id', 'maintext');
const text = await getQuote();
p.innerHTML = text[0] + " " + text[1][2];
console.log(p.innerText);
messageDiv.appendChild(p);
const pre = document.createElement("pre");
pre.setAttribute('id', 'ascii');
const asciiArt = text[2];
pre.innerHTML = asciiArt;
messageDiv.appendChild(pre);
//footer section
const inspFooter = document.getElementById('inspirationsource');
inspFooter.innerText = "Inspirational Author: " + text[3];
const bibleFooter = document.getElementById('biblesource');
bibleFooter.innerText = "Scripture Source: " + text[1][0] + " " + text[1][1]
}
makeQuote();