Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!