How to return an object created in a function?

AGx-07_162

I apologize if my title is confusing in any way. I'm trying to figure out how to properly do this. I'm trying to create an object whos key:values are other objects. See the code below. I'm testing in the Chrome console.

If I just do Characters = CharactersFn("male"); or var Characters = CharactersFn("male"); by itself I can create the object from the CharactersFn() function but when I try to do it via my whatAreYou() function I get no results. How do I do this properly?

Note: I'm still learning and just trying to get a grasp on how to do things properly.

var Characters,
    valueArr = [],      
    nameArr = [],           
    matchArr = [];

var CharactersFn = function (ans) {     //Are you male or female?   
    "use strict";
    if (ans === "male") {
        Characters = {
            47: aloy,
            snake: snake,
            drake: drake,
            cloud: cloud
        };
    }

    if (ans === "female") {
        Characters = {
            aloy: aloy,
            bayonetta: bayonetta,
            elizabeth: elizabeth,
            ellie: ellie
        };
    }
    return Characters;
};

function whatAreYou() {
    "use strict";
    var gender = prompt("0 or 1");

    if (gender === 0) {
        Characters = CharactersFn("female");
    }
    if (gender === 1) {
        Characters = CharactersFn("male");
    }
        return Characters;
}
Quentin
var gender = prompt("0 or 1");
if (gender === 0) {
if (gender === 1) {

The prompt function returns a string. The result will never match either of your if statements.

You need to compare to "0" and "1" not 0 and 1.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to return references to object created inside a method

From Dev

Angular2 - return observable of object created in map function

From Dev

How to pass an object in a dynamically created function call

From Dev

How can I return a local created object in C++?

From Dev

How do I return a list created inside a scheme function?

From Dev

How to return a dynamic object from operator function?

From Dev

How do you return an object from a function?

From Dev

How to return dynamic object from operator function?

From Dev

how to eval a cond case and return function object?

From Dev

How to pass a object though function-created-button

From Dev

How to create a function that creates a function to constantly return an object's key

From Dev

how to pass an object to a function and return the outcome back to the original function

From Dev

How to pass then() return object as input to then() function using NodeJS Map function

From Dev

How is this object being created?

From Dev

Return Object Outside of Function

From Dev

Return an object from a function

From Dev

Expose function and return object

From Dev

Return an object from a function

From Dev

Return an object with a function

From Dev

Keep object and reference to an object created inside a function

From Dev

What is the return type of an object created with CreateODBCDateTime()?

From Dev

NullPointerException is thrown, but the object is created and correctly return values

From Dev

Return the value of an object created in a runSync method

From Dev

C++ How to add objects to maps and return reference to new created object inside map

From Dev

C++ How to add objects to maps and return reference to new created object inside map

From Dev

How return a object inside a done function while the function expected to have a return value in typescript?

From Dev

How return a object inside a done function while the function expected to have a return value in typescript?

From Java

How to return anonymous object from one liner arrow function in javascript?

From Dev

How can I define a Typescript object return value for a function?

Related Related

  1. 1

    How to return references to object created inside a method

  2. 2

    Angular2 - return observable of object created in map function

  3. 3

    How to pass an object in a dynamically created function call

  4. 4

    How can I return a local created object in C++?

  5. 5

    How do I return a list created inside a scheme function?

  6. 6

    How to return a dynamic object from operator function?

  7. 7

    How do you return an object from a function?

  8. 8

    How to return dynamic object from operator function?

  9. 9

    how to eval a cond case and return function object?

  10. 10

    How to pass a object though function-created-button

  11. 11

    How to create a function that creates a function to constantly return an object's key

  12. 12

    how to pass an object to a function and return the outcome back to the original function

  13. 13

    How to pass then() return object as input to then() function using NodeJS Map function

  14. 14

    How is this object being created?

  15. 15

    Return Object Outside of Function

  16. 16

    Return an object from a function

  17. 17

    Expose function and return object

  18. 18

    Return an object from a function

  19. 19

    Return an object with a function

  20. 20

    Keep object and reference to an object created inside a function

  21. 21

    What is the return type of an object created with CreateODBCDateTime()?

  22. 22

    NullPointerException is thrown, but the object is created and correctly return values

  23. 23

    Return the value of an object created in a runSync method

  24. 24

    C++ How to add objects to maps and return reference to new created object inside map

  25. 25

    C++ How to add objects to maps and return reference to new created object inside map

  26. 26

    How return a object inside a done function while the function expected to have a return value in typescript?

  27. 27

    How return a object inside a done function while the function expected to have a return value in typescript?

  28. 28

    How to return anonymous object from one liner arrow function in javascript?

  29. 29

    How can I define a Typescript object return value for a function?

HotTag

Archive