Duvida JavaScript [closed]

-2

The structure below is a guide to how information is arranged. Implement in javascript the listAllDoctors() function that is responsible for storing the structure below containing their names and specialties. Note that the names and specialties will be listed in the DOM, as shown below, and the listing should remain the same as closing and reopening the browser.

var doctors = [
'rem',
'clack',
'bruce',
'jack'
];
var especialidades = [
'nefrologia',
'cardiologia',
'ortopedia',
'otorrino'
];

Output example:

Professionals - Specialties

  • Dr.rem-nephrology
  • Dr.clack-cardiology
  • Dr.bruce-orthopedics
  • Dr.jack-otorrino
asked by anonymous 07.11.2018 / 19:45

1 answer

1

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

        
    07.11.2018 / 20:25