samedi 26 novembre 2022

Random employee generator

i am currently working on a program that randomly generates first names, last names, date of birth, working hours for a certain number of employees. I'm stuck on not knowing how to write out a nice clear output. For example :

const dtoOut = [
  {
    gender: "male",
    birthdate: "1993-08-07T00:00:00.000Z",
    name: "John",
    surname: "Doe",
    workload: 40
  },

Next, I need to write the date of birth by min and max age, but but I need to put it on the input and not on the console.log


function getRandomDate(startDate, endDate) {
    const minValue = startDate.getTime();
    const maxValue = endDate.getTime();
    const timestamp = Math.floor(Math.random() * (maxValue - minValue + 1) + minValue);
    return new Date(timestamp);
}

console.log(getRandomDate(new Date(1987,0,1), new Date(2003,11,31)));

Here is the full program :


const females = ["LIST OF FEMALE NAMES"]

const males = ["LIST OF MALE NAMES"]

const maleSurname = ["LIST OF MALE SURNAMES"]

const femaleSurname = ["LIST OF FEMALE SURNAMES"]

const gender = ["male", "female"];

const workload = ["10","20","30","40"];

var count = (10);

const dtoIn = {};

function main (dtoIn,dtoOut){


    let randomDateOfBirth =  {}; // -..-    


}


while (count > 0){
const randomGender = [Math.floor(Math.random() * gender.length)];  

console.log(gender[randomGender])
const randomWorkload = [Math.floor(Math.random() * workload.length)];  
console.log(workload[randomWorkload])



    if (gender[randomGender] === "female") {
    
        const randomFemaleName = [Math.floor(Math.random() * females.length)];
        const randomFemaleSurname = [Math.floor(Math.random() * femaleSurname.length)];
        
        console.log(females[randomFemaleName])
        console.log(femaleSurname[randomFemaleSurname])
        count = count - 1;

    }

    else {
        
        const randomMaleName = [Math.floor(Math.random() * males.length)];
        const randomMaleSurname = [Math.floor(Math.random() * maleSurname.length)];
        
        console.log(males[randomMaleName])
        console.log(maleSurname[randomMaleSurname])
        count = count - 1;
}
}


Thanks you for every help .. David.

So if someone could possibly help me out i will pay with gold, if i have some LMAO . :D




Aucun commentaire:

Enregistrer un commentaire