Hi all!
I have the following loop:
function timeConstruct() {
let s = 540;
var e = 1080;
var a = 30
var n = 18
let b = s
while((b) < (e-a)){
b = (s+=a)
timeConvert(b)
}
}
and time constructor:
function timeConvert(num) {
const hours = Math.floor(num / 60);
const minutes = num % 60;
if (minutes.toLocaleString().length === 1) {
let newMinutes = "0" + minutes.toLocaleString();
if (hours > 12) {
let h = hours - 12;
let newHours = h.toLocaleString();
let time = newHours + ":" + newMinutes + "PM"
session.setItem("timeOutput", time);
} else {
let newHours = hours.toLocaleString();
let time = newHours + ":" + newMinutes + "AM"
console.log(time);
session.setItem("timeOutput", time);
}
} else {
let newMinutes = minutes.toLocaleString();
if (hours > 12) {
let h = hours - 12;
let newHours = h.toLocaleString();
let time = newHours + ":" + newMinutes + "PM"
console.log(time);
session.setItem("timeOutput", time);
} else {
let newHours = hours.toLocaleString();
let time = newHours + ":" + newMinutes + "AM"
console.log(time);
session.setItem("timeOutput", time);
}
}
return(session.getItem("timeOutput"))
}
They both work great individually; however, I want to push the results of the timeConstruct loop into an array with the values generated from
while((b) < (e-a)){
b = (s+=a)
timeConvert(b)
}
Currently, they are all properly constructed and logged in the console, I just can’t see to push them to an array within the timeConvert loop.
Any help would be awesome!