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

  • Home
  • SEARCH
  • 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 8329347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:45:11+00:00 2026-06-09T01:45:11+00:00

Is there a way to make this prettier; if ($(#Input).text === A) { sOutput

  • 0

Is there a way to make this prettier;

if ($("#Input").text === "A") { sOutput = "a"; lColor = "red"; }
if ($("#Input").text === "B") { sOutput = "b"; lColor = "orange"; }
if ($("#Input").text === "C") { sOutput = "c"; lColor = "yellow"; }
if ($("#Input").text === "D") { sOutput = "d"; lColor = "green"; }
if ($("#Input").text === "E") { sOutput = "e"; lColor = "blue"; }
if ($("#Input").text === "F") { sOutput = "f"; lColor = "violet"; }
...

The real code is much more extensive, with && and || between different variables. But each line follows the same syntax save the ‘letter(s)’ I’m looking for, and the variables I set. It just feels wasteful to me that I have so many ifs.

*The code is dummy code to illustrate my point.

EDIT

Dummy code isn’t illustrating my point, so here’s a sample of the real;

    if ($(".Fig_Main").hasClass("Active")) {
        sect_1 =  (($(".Fig_A").hasClass("Active")) && ($(".Fig_1").hasClass("Active"))) ? "Slide_A1"
              : (($(".Fig_A").hasClass("Active")) && ($(".Fig_B").hasClass("Active"))) ? "Slide_AB"
              : (($(".Fig_1").hasClass("Active")) && ($(".Fig_B").hasClass("Active"))) ? "Slide_1B"
              : (($(".Fig_1").hasClass("Active")) && ($(".Fig_3").hasClass("Active"))) ? "Slide_13"
              ...

I have this block (which is several lines longer) repeated a few times, for a different sect_# each time, and resultant set value (Slide_XY).

All the current suggestions are much appreciated. Keep it coming.

  • 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-09T01:45:13+00:00Added an answer on June 9, 2026 at 1:45 am

    You could do something like this:

    var dic = {
      "a": "red",
      "b": "orange",
      "c": "yellow",
      "d": "green",
      "e": "blue",
      "f": "violet"
    };
    
    sOutput = $("#Input").text().toLowerCase();
    lColor = dic[sOutput];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to make this code more simplified? <input type=text id=tags />
Is there any way to make this code shorter? price1 = input(\nEnter price here:
Is there a way to make this code smaller into 1 block? $('#product INPUT:checked').each(function
Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String
Is there a way to make this line shorter? bool pass = d !=
Is there any way to make this work in Java? public static void change(List<?
Is there a way to make this method generic so I can return a
Essentially, is there any way to make this code legal? main = print .
MyClass c = 10; Is there any way to make this code work? I
Is there any better way to make this query work? I'm looking for a

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.