Answer the question
In order to leave comments, you need to log in
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
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>`
}
}
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!
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.
וַיֹּאמֶר אֱלֹהִים, יְהִי אוֹר; וַיְהִי-אוֹר
Книга Глава:Стих
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question