Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:55:14+00:00 2026-06-06T11:55:14+00:00

I have 10 variables. q1 through q10 my script is as follows: if (q1

  • 0

I have 10 variables. q1 through q10

my script is as follows:

if (q1 == '1') { q1 = 'Yes'; 
} else if (q1 == '2') { q1 = 'No';
} else { q1 = 'Did Not Answer'; }

I already typed this out for all 10. I am not sure if I can insert another variable into this variable.

I’m trying to do something like this:

var ex = '1';
while (ex < 11) { 
if (q[ex] == '1') { q[ex] = 'Yes'; ex++;
} else if (q[ex] == '0') { q[ex] = 'No'; ex++;
} else { q[ex] = 'Did Not Answer'; ex++ }

Basically I want to eliminate 4 lines of code x 10 variables.

[ex] is a variable inside the variable (to represent q1, determine q1 = Yes, No, or Did Not Answer, then add 1 to q[ex] which would now be q2….

I understand that the [] may not be correct, I just don’t know how to explain this in a way that is understandable.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:55:17+00:00Added an answer on June 6, 2026 at 11:55 am

    This wouldn’t limit it down all the way but you could create a function

    translate = function(v)
    {
        if (v === '1') { 
            v = 'Yes'; 
        } else if (v === '2') { 
            v = 'No';
        } else { 
            v = 'Did Not Answer'; 
        }
      return var
    }
    

    Then call translate(q1) etc for each variable. That would move it to ~16 lines rather than 40 and avoid repeating code.

    You also could reform your variables as an array of variables and loop through quickly like that, but I don’t know where they are all being defined and how that would work for you.
    EDIT: Bergi has a good example of this. If you can reform your variables like that, that is the best way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single page website that changes content based on variables passed through
i have been trying to pass some variables to model through the controller function
I have two variables in a jquery code and if item.a not exist, it
I have these variables: boost::regex re //regular expression to use std::string stringToChange //replace this
I need some help with this! I´m passing multiple variables through URL and on
I am having trouble getting this to work. I have variables initiated in main
I have 10 variables: $c1=a; through $c10=j; I also have a variable $i=1; I'm
I have three variables that may or may not contain data. let's call them
I have one php function that receives drop down variables through javascript. The variables
Trying to figure out how to read in multiple variables through a file. for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.