I'm sorry if my title is a bit confusing. I'm currently working on creating an object that contains key-value pairs of other objects. Below is the code snippet I'm testing in the Chrome console.
When I try to create the object using the CharactersFn()
function directly with
Characters = CharactersFn("male");
or var Characters = CharactersFn("male");
, it works fine. However, when I attempt to do it through my whatAreYou()
function, I don't get the desired results. Can anyone assist me with the correct approach to achieve this?
Disclaimer: I'm still in the learning phase and trying my best to understand the right way to accomplish tasks.
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;
}