<!-- JavaScript:Basics plus code snippet 3. --> <!-- Selection: building an 'if else' conditional. Calling a function from another function. --> <!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> <script language="JavaScript" type="text/javascript"> <!-- begin function equal(number) { return number*2 } /* this second function calls the function above if the numbers are the same */ // note the use of 'NOT' '!' in the 'if' condition // note use of equality operator '==' function add(firstNumber,secondNumber) { if (!(firstNumber==secondNumber)) // this line executes if the 'if' condition is true { return firstNumber+secondNumber } else // this line executes if the 'if' condition is false { return equal(firstNumber) } } // end --> </script> </head> <body> <script language="JavaScript" type="text/javascript"> <!-- begin var myFirstNumber var mySecondNumber myFirstNumber=8 mySecondNumber=8 document.write(add(myFirstNumber,mySecondNumber)) // end --> </script> </body> </html>