Welcome to Stack Overflow in English! To learn more, take a look at the code of conduct .
Did you translate this or is the text just the same? It seems to lack information. The statement is not very clear. I believe that the function that does what is asked in the statement would look something like this:
var doctors = [ 'rem', 'clack', 'bruce', 'jack' ];
var especialidades = [ 'nefrologia', 'cardiologia', 'ortopedia', 'otorrino' ];
localStorage.setItem('doctors', JSON.stringify(doctors));
localStorage.setItem('especialidades', JSON.stringify(especialidades));
function listAllDoctors(){
let doctors = localStorage.getItem('doctors') ? JSON.parse(localStorage.getItem('doctors')) : [];
let especialidades = localStorage.getItem('especialidades') ? JSON.parse(localStorage.getItem('especialidades')) : [];
for (let i = 0; i < doctors.length; i++){
let doctor = doctors[i];
let espec = especialidades[i];
document.write("Dr." + doctor + "-" + espec);
}
}
listAllDoctors();
You can see the example working here: link
I say that the statement is not clear by some questions:
The statement says that the listAllDoctors
function will store, but will not print to the DOM.
Will the arrays with the elements be sent by parameters to the function, or will they be fixed in this example? If they are fixed, discard the use of Local Storage for this.
As in the example I showed, the results will always be the same, but the text does not clearly state what I did.
In short, the function would be this, or some variation of it, but it's already a good starting point.
References:
How to use Local Storage with JavaScript