import { log, logTitle } from "logger";
var persons = [
{name: "Alex", age:22},
{name: "Maria", age:30}
]
var number = 0;
for (var i = 0; i <= persons.length; i++) {
log(persons[i].name);
log(persons[i].age);
log("----------------");
log(number)
};
while(number < 5) {
log(number);
number += 1;
};
The for loop will display output on the screen, however, in this case, the log statements within the while loop are not displayed. By rearranging the loops and putting the while loop first, both sets of logs run successfully as shown below:
while(number < 5) {
log(number);
number += 1;
};
for (var i = 0; i <= persons.length; i++) {
log(persons[i].name);
log(persons[i].age);
log("----------------");
log(number)
};
In addition, if the for loop is commented out, the log statements within the while loop become visible.
Lastly, provided below is the code snippet from the imported logger file:
import $ from 'jquery';
export const log = content => $('#content').append("<i style = 'color: black' class = 'fa fa-terminal'> </i> " + content + "<br>" );
export const logTitle = title => $('#title').append(title);