Search the Community
Showing results for tags 'iseven.php'.
-
Write a script that uses a conditional operator to determine whether a variable contains a number and whether the number is even. You need to use the is_numeric() function and the conditional operator. For floating-point numbers, you need to use the round() function to convert the value to the nearest whole number. Save the document as IsEven.php. Reinforcement Exercises1-6 This has been a hard to find solution and I am submitting mine. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd%22>"]http://www.w3.org/TR...l1-strict.dtd">[/url] <html xmlns="[url="http://www.w3.org/1999/xhtml%22>"]http://www.w3.org/1999/xhtml">[/url] <head> <title>PHPIsEven1-6</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> </head> <body> <form action="isEven.php" method="post"> Input Number:<input type="text" size="36" maxlength="36" name="Fnumber">:<br /> <input type="submit" value="submit" name="submit"><br /> </form><br /> <?php // Carl Skeel # 2012/09/24 $Fnumber = $_POST['Fnumber']; $Number = $Fnumber; if (is_numeric($Number)){ $Result = ""; if( $Number & 1 ){ $Result = "The number (" . round($Number) . ") and is numeric and it's odd!"; }else{ $Result = "The number (" . round($Number) . ") and is numeric and it's even!"; } }else{ $Result = "($Number) is not numeric!"; } echo $Result; ?> </body> </html> I hope this helps anyone on this one! IsEven.php
- 8 replies
-
- conditional operator
- is_numeric() function
- (and 3 more)