I am trying to get a random word when the endpoint '/randomword' is hit. I used Math.random to get a random number between the array index numbers- and try to get a random word by accessing an element with a random index. This code does give me a random word at first but it doesn't change with each get request.
I wrote this and it does return a random word but it doesn't change with each get request.
rInt = getRandomInt(2)
function getRandomInt(max) {return Math.floor(Math.random() * max);}
wordList = [
{"word": "abase",
"type": "verb",
"meaning": "lower in position; degrade"},
{"word": "abbess",
"type": "verb",
"meaning": "lady superior of a nunnery"},
{"word": "abbot",
"type": "noun",
"meaning": "head of monks"}
]
randomWord = wordList[rInt];//console.log(randomWord);
app.get('/randomword', function (req, res) {res.status(200).send(randomword)})