What is the best way to refactor this JS for my random quote generator? The getLifeQuote and getTravelQuote functions do the same task. I've tried several things and it won't work. Here is the code:
lifeBtn.addEventListener('click', getLifeQuote);
travelBtn.addEventListener('click', getTravelQuote);
function getLifeQuote(){
let sentenceFrag1 = ['Being happy', 'Living contently', 'Enjoying your life', 'Taking it easy', 'Trying to relax']
let sentenceFrag2 = ['is a challenge', 'is worth it', 'is a possibility', 'is the goal', 'can be done'];
let sentenceFrag3 = ['for a brighter future.', 'to soar higher.', 'for a better you.', 'to achieve greatness.', 'for a stress-free day.'];
let inputValue = document.getElementById("userInput").value;
let quote = '';
for (i = 0; i < inputValue; i++) {
quote += `${sentenceFrag1[Math.floor(Math.random() * sentenceFrag1.length)]} ${sentenceFrag2[Math.floor(Math.random() * sentenceFrag2.length)] }${sentenceFrag3[Math.floor(Math.random() * sentenceFrag3.length)]} <br> <br>`
quoteArea.innerHTML= quote;
}
return quote;
}
function getTravelQuote(){
let sentenceFrag1 = ['Traveling', 'Explorinig', 'Seeing the world', 'Going on a journey', 'Hitchhiking']
let sentenceFrag2 = ['is the ticket to', 'opens your eyes to', 'grants access to', 'opens doors to', 'can make you experience'];
let sentenceFrag3 = ['the earth around us.', 'the lives of others.', 'the many cultures different from your own.', 'the adventures that await.', 'the joys of the world.'];
let inputValue = document.getElementById("userInput").value;
let quote = '';
for (i = 0; i < inputValue; i++) {
quote += `${sentenceFrag1[Math.floor(Math.random() * sentenceFrag1.length)]} ${sentenceFrag2[Math.floor(Math.random() * sentenceFrag2.length)] }${sentenceFrag3[Math.floor(Math.random() * sentenceFrag3.length)]} <br> <br>`
quoteArea.innerHTML= quote;
}
return quote;
}