The pen is here: https://codepen.io/BradCoffield/pen/WEWXqO
I have a getJSON and inside of it I'm processing returned data and building what should get sent to the HTML using 2 .forEach
I want to pull the results of each .forEach
, concatenate them and append them to an ID. But the variables aren't accessible to the outer area of the function and I don't know what to do.
$(document).ready(function () {
$.getJSON("https://api3.libcal.com/api_hours_grid.php?iid=000&format=json&weeks=1&systemTime=0&callback=?", function (json) {
var day0 = (json.locations[0].weeks[0].Sunday);
var day1 = (json.locations[0].weeks[0].Monday);
var day2 = (json.locations[0].weeks[0].Tuesday);
var day3 = (json.locations[0].weeks[0].Wednesday);
var day4 = (json.locations[0].weeks[0].Thursday);
var day5 = (json.locations[0].weeks[0].Friday);
var day6 = (json.locations[0].weeks[0].Saturday);
var days = [day0, day1, day2, day3, day4, day5];
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
dayNames.forEach(function (foo) {
var someContent = "<li id='" + foo + '-hours'+"'><span class='day-of-week'>" + foo + ", "
});
days.forEach(function (element) {
var dayDate = element.date
var dayDay = element.rendered
if (dayDate[5] === '0') {
dayDate = dayDate.substr(6)
} else {
dayDate = dayDate.substr(5)
}
var moreContent = "" + dayDate + ":</span> " + "<span class='dates'>" + dayDay + "</li>"
});
var forHTML = someContent + moreContent;
$('#this-weeks-hours').append(forHTML);
});});