Hi all. I always receive great help here, much appreciated
So I’m trying to pass a variable into a function , that should then insert it into a literal template. Like so:
async function displayData(url,displayWhere,displayCurrent,displayPrevious){
const data= await(getJson(url));
//console.log(data);
let stringDaily='',stringWeekly='';
data.forEach((element,index) => {
const results= document.querySelector(displayWhere[index]);
stringDaily = `<h2>${element.title}</h2>
<p class='fs-1'>
${displayCurrent}hrs //this does not work.
</p>
<p>
${element.timeframes.daily.previous}hrs
</p>
`
$(results).append(stringDaily);
});
}
And I call this function so:
let currentDay = 'element.timeframes.daily.current';
let previousDay= 'element.timeframes.daily.previous';
displayData(url, displayWhere,currentDay,previousDay);
Now I know it passes it as a string, so maybe that’s problem? It becomes this?
${"element.timeframes.daily.previous"}hrs
How do I solve this and is this even possible?
Thanks