Answers for "ternary operator"

45

ternary operator

(condition) ? (if true, do this) : (otherwise, do this)
Posted by: Guest on May-14-2020
4

ternary operator

// (condition) ? (if true, do this) : (otherwise, do this)
const hasAccount = true
// let userDisplayMessage
// if (hasAccount) {
//   userDisplayMessage = 'Welcome Back'
// } else {
//   userDisplayMessage = 'Please Sign Up'
// }
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
Posted by: Guest on April-27-2021
3

ternary operator

// It is bascially an if else statement but is an operator
// Heres a program to get the largest of 3 numbers
import java.util.Scanner; 

  public class Program_19{ 
  static void main(){ 

    Scanner sc = new Scanner(System.in); 

    System.out.println("Enter Number 1 [int]: "); 

    int num1 = sc.nextInt(); 

    System.out.println("Enter Number 2 [int]: "); 

    int num2 = sc.nextInt(); 

    System.out.println("Enter Number 3 [int]: "); 

    int num3 = sc.nextInt(); 

    int largest = (num1>num2)? ((num1>num3)?num1:num3) : ((num2>num3)? num2:num3); 

    System.out.println(largest+" is the largest among the 3 numbers"); 

  } 

}
Posted by: Guest on July-28-2021
4

Ternary Operator

condition ? expression-if-true : expression-if-false;

function findGreater(a, b) {
  return a > b ? "a is greater" : "b is greater";
}
Posted by: Guest on December-28-2020
2

ternary operator

isMember ? '$2.00' : '$10.00'
// isMember true =>  output: "$2.00"

// isMember false =>  output: "$10.00"

// isMember null =>  output: "$10.00"
Posted by: Guest on September-23-2020
0

ternary operator

// syntax:
condition ? console.log("true") : console.log("false");
// e.g:
let n = 15;
n % 2 === 0 ? console.log("even number") : console.log("odd number");
Posted by: Guest on May-22-2021
1

ternary operator

if ($scope.SearchSalesOrderAndCompanyName !== undefined && $scope.SearchSalesOrderAndCompanyName != null ) {
            SearchCriteria += " AND [SalesOrderNo] LIKE '%" + $scope.SearchSalesOrderAndCompanyName + "%' OR ([SO].[CompanyNameOnBill] LIKE '%" + $scope.SearchSalesOrderAndCompanyName + "%')";
        }
        if ($scope.FromDate !== undefined && $scope.FromDate !=null) {
            SearchCriteria += " AND [SO].[SalesOrderDate] LIKE '%" + $scope.FromDate + "%'";
        }
Posted by: Guest on January-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language