I am new to programming (this is my first course). I am taking a course and the
ID: 3541246 • Letter: I
Question
I am new to programming (this is my first course). I am taking a course and the text is PHP Programming w/ MySQL. I cannot figure out how to do the last exercise in chapter 1. Exercise 1-6. The problem is this:
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 fl oating-point numbers, you need to use the round() function to
convert the value to the nearest whole number. Save the document as
IsEven.php.
Thanks
Explanation / Answer
Sorry for the previous answers.. I think this code satisfies all the conditions and works fine if you paste the code as is. try it
<?php
$variable = 4.23; // just some random value
$k = is_numeric($variable)? (round($variable)%2==0 ? "<h1>Given Number is Even</h1>" : "<h1>Given Number is Odd</h1>") : "<h1>Given input is not Numeric</h1>"; // printing the result (Odd)
echo $k;
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.