<!-- JavaScript:Basics plus code snippet 4a. --> <!-- Shortcut notation 'if else' conditional sometimes known as a ternary operator with the syntax '?:'. --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- Code source: http://www.justfigures.co.uk/ --> <!-- A resource for web developers using XHTML, CSS, JavaScript, PHP --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>View code snippet page</title> </head> <body> <script language="JavaScript" type="text/javascript"> //<![CDATA[ /* a conditional expression equivalent to an 'if then else' and incorporated in a ternary statement: condition ? if true : if false */ var testNumber1; testNumber1 = 2; document.write(testNumber1 == 2 ? "Test number is 2" : "Number is " + testNumber1); document.write("<br />"); var testNumber2; testNumber2 = 3; document.write(testNumber2 == 2 ? "Test number is 2" : "Number is " + testNumber2); //]]> </script> </body> </html>