-1

I am wanting to make a character personality test(for my fictional characters)

I know I am going to have to have variables equaling arrays like this:

// var personality = [gender, age, muscularity, trait_1, trait_2, etc.];

I know the variable = array isn't working so I commented it out. I am going to need variables for each question and a lot of if/else if/else statements.

I start with an alert() statement where I ask the question "What is your gender?" I think I need to change this to prompt() for it to accept an answer.

But how am I going to get all these var = "string" and if/else statements and var = [array] statements into a reasonable, pure JS personality test?

I know the plan(gender first, then age, then other physical characteristics, then socio-emotional characteristics, then other characteristics) but I need some help here.

I know that the if/elseif/else statements would lead to more and more prompts and some would be male specific and some would be female specific. So I would have all these nested statements like this:

if (variable = "string") {
    prompt("Next question");
    var a(generic variable that could refer to anything) = [array(prompt results)];
} else {
    prompt("Next question");
    var b(again generic variable) = [array(prompt results)];
}

etc.

So how could I get the arrays to have the possible results and if what is typed in is undefined(out of the array) not allow it to continue?

And how could I get this last personality array to take all previous variables into consideration and have particular combinations equal particular personalities without n * 10^x if/else statements?

iHowell
  • 2,263
  • 1
  • 25
  • 49
Caters
  • 147
  • 1
  • 10

1 Answers1

0

Firstly, you are using JavaScript, so objects/dictionaries are your friend. They are like arrays, but have keys for each entry.

Secondly, you should have a list of questions that you present from with varying answers. Using prompts (pure JavaScript alert that is) is not a good idea, since the responses are so limited. Instead, I would recommend looking into modals and using those to display many more results for each question, or a text box for them to fill out.

I think that epascarello had a pretty good idea with checking for null or an empty string for if a question hasn't been answered and then presenting it again.

iHowell
  • 2,263
  • 1
  • 25
  • 49