D
D
Darius2020-08-11 08:01:10
JavaScript
Darius, 2020-08-11 08:01:10

How to get a random Bible verse?

Help write a function that will receive a random verse from the Bible. And tell me in what form is it better to store the Bible on the server for this task?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Darius, 2020-08-11
@Darij

Found the Bible in JSON format.
Wrote this code:

let wrapper = document.querySelector('.wrapper')
let request = new XMLHttpRequest();
request.open('GET', 'http://127.0.0.1:5500/rst.json');
request.responseType = 'text';
request.send();
function random(min, max) {
   return Math.floor(Math.random() * (max - min) + min)
}
request.onload = function () {
   var superHeroesText = request.response;
   var superHeroes = JSON.parse(superHeroesText)
   for (let key in superHeroes) {
      let getAllBooks = superHeroes[key]
      let getBook = getAllBooks[random(0, 66)]
      let getAllChapters = getBook['Chapters']
      let getChapterLength = getAllChapters.length
      let getChapter = getAllChapters[random(0, getChapterLength)]
      let getAllVerses = getChapter['Verses']
      let getVersesLength = getAllVerses.length
      let getVers = getAllVerses[random(0, getVersesLength)]
      let point = getVers['Text']
      console.log(getBook);

      wrapper.innerHTML = `<div class="bible-text">${point}</div>`
      wrapper.innerHTML += `<div class="bible-scr">(${getBook['BookName']} ${getChapter['ChapterId']}:${getVers['VerseId']})</div>`
   }
}

Everything works great, thanks everyone!

E
Eugene Surname, 2020-08-11
@EvGenN9845

You can imagine the bible as an array, and the verses will be the components of this array. How to organize it all is described in detail HERE!

R
Roman Mirilaczvili, 2020-08-11
@2ord

You can store the Bible line by line (verse = line).
Let's say
Бытие 1:3

And God said: let there be light. And there was light.

in Hebrew
וַיֹּאמֶר אֱלֹהִים, יְהִי אוֹר; וַיְהִי-אוֹר

Can be represented as Книга Глава:Стих
Chapter:Verse (chapter:verse) can be represented (encoded) with both literal and numerical values, depending on the language.
If you do not need to go through the chapters-verses in order, then it is enough to store 3 columns in the DBMS: bible_version, book, verse_reference.
bible_version - Synodal translation of
book - Genesis
verse_reference - 1:3
https://en.wikipedia.org/wiki/Chapters_and_verses_...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question