Generate random emails

Asked

Viewed 137 times

0

I’m doing an exercise that I’m cracking head, I have to create random emails from object array with fictitious client data, using a part of the nome and of cpf and I’m not getting it, someone could explain to me a way to do.

let clientes = [ 
    { nome: 'Kelvin Silva Sena', cpf: '10286741474', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Amyson Jhonata Da Silva', cpf: '10287054411', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Matheus Correa Da Silva', cpf: '10287259498', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Janekely Batista Dos Santos', cpf: '10288003470', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Luan Marcondes Alves De Souza', cpf: '10288469402', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Neidi Lucia Ignacio', cpf: '35331701949 ', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Neidi Lucia Ignacio ', cpf: '35331701949', email: '[email protected]', senha: 'passw:Abcd1234' },
    { nome: 'Neidi Lucia Ignacio', cpf: '35331701949', email: '[email protected]', senha: 'passw:Abcd1234' },
]

//preciso criar uma função

function gerarEmail() {
    let dominios= ['@gmail.com', '@outlook.com', '@bol.com.br']
    //funcao para gerar email aleatorio com partes do nome + cpf
    //examplo linha 1: [email protected]

}
  • and what the array clients are for?

1 answer

2

following by its array of clients...

function gerarEmail() {
    let dominios= ['@gmail.com', '@outlook.com', '@bol.com.br']
    for(var i=0;i<clientes.length;i++){
        let label   = clientes[i].nome.split(' ');
        let email   = label[0]+clientes[i].cpf+dominios[Math.floor(Math.random() * 
       dominios.length)];
        document.write(email+"<br/>");    
    }
 }

 gerarEmail();

I set up a loop FOR to iterate on each client of your listing, then I used the split javascript by breaking the name string of each client between spaces, generating an array that has been named here as a label. I concatenated the first position of this array, which comprises as the first name of each client with the whole Cpf. Then I just generated a random number that spans from zero to the total of items in your domain array, concatenating into the string variable email. Last I had print breaking a line.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.