Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

136
Vistas
How do you get the values from a function in javascript?

I am very new to the Javascript and I am wondering how I can get the values from a function.

From my given code I would like to get the values of TheName, TheHeight, and TheGender, TheSexuality when I run the function so that I can use them for other purposes in my program.

Code:

function prng ()
{
    var Name = Object.values(person.Names);
    var Height = Object.values(person.Heights);
    var Gender = Object.values(person.Genders);
    var Sexuality = Object.values(person.Sexualities);
    var TheName = Name[Math.floor(Math.random() * Name.length)];
    var TheHeight = Height[Math.floor(Math.random() * Height.length)];
    var TheGender = Gender[Math.floor(Math.random() * Gender.length)];
    var TheSexuality = Sexuality[Math.floor(Math.random() * Sexuality.length)];
    console.log('Name: ' + TheName + ', Height: ' + TheHeight + 
    ', Gender: ' + TheGender + ', Sexuality: ' + TheSexuality);
}

Any help would be greatly appreciated. :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

you write something like that:

function nameYourFunction () { ... instead of console.log(...) you write: return 'Name: ' + TheName +...+ TheSexuality;

}

or you add all varibles to one object like that: https://www.w3schools.com/js/js_objects.asp

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can define object inline and return it like this

    function prng ()
    {
        var person = {Names:'xx' , Heights:123,Genders:'male',Sexualities:'',};
        var Name = Object.values(person.Names);
        var Height = person.Heights;
        var Gender = Object.values(person.Genders);
        var Sexuality = Object.values(person.Sexualities);
        var TheName = Name[Math.floor(Math.random() * Name.length)];
        var TheHeight = Height[Math.floor(Math.random() * Height.length)];
        var TheGender = Gender[Math.floor(Math.random() * Gender.length)];
        var TheSexuality = Sexuality[Math.floor(Math.random() * Sexuality.length)];
        return {Name : TheName ,Height: TheHeight, Gender:TheGender,Sexuality: TheSexuality};
    }

    var v = prng();
    console.log(v);
    

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda