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 9249517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:12:50+00:00 2026-06-18T10:12:50+00:00

Rather than use an if else statement, I’m trying to use the ternary operator

  • 0

Rather than use an if else statement, I’m trying to use the ternary operator but have a syntax error somewhere in my statement.

Can someone tell me where I am going wrong?

Statement is:

my_alert(status ? ('Accepted', 'alert-success') : ('Declined', 'alert-info'))
  • my_alert is a function which has 2 parameters.
  • Status just evaluates to true or false.
  • When I pass more than 1 parameter into the above expression, it doesn’t like the use of the comma.

In chrome and firefox when the function runs it displays ‘alert-success’ or ‘alert-info’. It misses out the first parameter.

I’ve looked on stackoverflow for the answer but by all means it’s telling me that what i’m doing is correct.

Any help would be great.

  • 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-18T10:12:53+00:00Added an answer on June 18, 2026 at 10:12 am

    Alternatively, you could just wrap the function call in the ternary statement…

    status ? my_alert("Accepted", "alert-success") : my_alert("Declined", "alert-info");
    

    UPDATE:

    Robin van Baalen makes a good suggestion…

    my_alert.apply(this, status ? ["Accepted", "alert-success"] : ["Declined", "alert-info"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a drag to select feature, but rather than select a
Is there a method to use contain rather than equal in case statement? For
Rather than reinvent the wheel I would like to use Outlook to manage my
I use XmlSerializer extensively and rather than allowing .NET to generate the necessary serialization
Is it possible to use horizontal scrolling rather than text wrapping in a code
I want to use the June 2010 SDK rather than the Windows 8 SDK
Why would one use the AlertDialog.Builder class rather than the methods directly available to
Is it any faster to use myString.replace(/foo/g,bar) rather than myString.split(foo).join(bar) for long strings in
Python documentation to Popen states: Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read
Why would one use realloc() function to resize an dynamically allocated array rather than

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.