I need help


#1

$eConstant = M_E;
$roundNumber1 = round($eConstant, 0);
print "This number is integer {$roundNumber1}";
?>

<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen

$piConstant = M_E;

$roundNumber2 = round($piConstant, 3);

print "This number is rounded to 3 places after comma {$roundNumber2}";
?>

<?php
// Try rounding a floating point number to 3 decimal places
// and print it to the screen

?>

i dont know whats wrong ive tried suggestions and its been like this for over a month i need to know what to do cause i cant move on
the erreor code is opps try again


#2

Did you mean, $piConstant = M_PI?


#3

now the error code says Your second call to round() should print a floating point number with exactly 3 digits after the decimal.


#4

Please post a link to the exercise so we can determine what is expected and test your code. Thanks.

I'm not sure you understand what M_E is. Do you know what it represents?


#5

https://www.codecademy.com/courses/web-beginner-en-7I7Xm/0/4?curriculum_id=5124ef4c78d510dd89003eb8


#6

To repeat,

I'm not sure you understand what M_E is. Do you know what it represents?

I cannot help you further until you answer this question.


#7

no i dont not really


#8

What level of math have you reached? Have you learned about math constants? (constants in nature)


#9

freshman year and yes I have reached math constants


#10

Great, then you know about e and pi. Many computer languages treat constants as, GLOBAL_CONSTANTS (not yelling, only demonstrating how they are written).

M_E   // e

M_PI  // pi
Click to view table of some PHP constants

Constant    Value                   Meaning

M_PI        3.14159265358979323846  Pi

M_PI_2      1.57079632679489661923  Pi/2

M_PI_4      0.78539816339744830962  Pi/4

M_1_PI      0.31830988618379067154  1/Pi

M_2_PI      0.63661977236758134308  2/Pi

M_SQRTPI    1.77245385090551602729  sqrt(M_PI)

M_2_SQRTPI  1.12837916709551257390  2/sqrt(M_PI)

M_SQRT2     1.41421356237309504880  sqrt(2)

M_SQRT3     1.73205080756887729352  sqrt(3)

M_SQRT1_2   0.70710678118654752440  1/sqrt(2)

When we define a variable, it is best if it describes what it represents without misleading the reader.

$eConstant = M_E;

$piConstant = M_PI;

First rule of readable code--Semantics.

That's the preamble. Now to examine the instructions and your code...

The author organized the editor with instructions on where to write your code for a given task. That would be the first concern with your code above. We cannot tell which instruction is being followed where.

The <?php tag is very important, as all this code is embedded in that tag, which ends with ?>. The tag means, pre-processed html. It is important that any code we write is inside the php tag.

<p>
<?php
    // Try rounding a floating point number to an integer
    // and print it to the screen

    print round(M_E, 0);

?>
</p>

Notice that the HTML tags are not inside the PHP. Only the code. The print statement generates the text node of the paragraph element it is contained in.

<p>
<?php
    // Try rounding a floating point number to 3 decimal places
    // and print it to the screen

    print round(M_PI, 3);

?>
</p>

Most importantly, notice that above we have not embellished the code in any way. Simple and sweet, and all that is expected for the exercise.


#11

ok so that not the answer and im still confused


#12

Did you organize the code according to the author's wishes?

Please re-post your code (in a reply). Thanks.


#13

i belive so yes whats the answer cuz ive been stuck here for a month


#14

I've already given it to you; that's why I need to see your code again.


#15

https://www.codecademy.com/courses/web-beginner-en-7I7Xm/0/4?curriculum_id=5124ef4c78d510dd89003eb8


#16

All I see at that link is my own code for this exercise. We cannot see each other's workspace. Please copy and paste your code into a reply. Thanks.


#17

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.