0

Constants value

Why I should write age only 28 in this case?: <?php define(“AGE”, 28); ?> Because if I write 25 for example it is a wrong answer.

23rd May 2019, 1:03 PM
Екатерина Рассоха
Екатерина Рассоха - avatar
9 Respuestas
+ 1
no, i don’t. Because in other examples age = 25 or other. Why only 28?
23rd May 2019, 1:10 PM
Екатерина Рассоха
Екатерина Рассоха - avatar
+ 6
It is considered wrong answer because the lesson quiz specifically tells to create a constant named "AGE" with value 28. Having been instructed just that, of course assigning a constant value other than 28 would be wrong : ) https://www.sololearn.com/learn/PHP/2331/
23rd May 2019, 2:58 PM
Ipang
+ 6
AgentSmith, my pleasure, and good job! 👍
23rd May 2019, 3:28 PM
Ipang
+ 4
define(“AGE”, 28); ^That's the constant you defined, so it'll always be 28. However, you can change the 28 to whatever number you want in the definition for it, but the rest of the code won't be able to change it since it is a constant. Get what I mean? Typically, AGE should be dynamic and not a constant since the age of anything changes over time. A good example of a constant could be the number of days in the week, days in the year, seconds in a minute, minutes in an hour, year something was created, etc... - anything that typically doesn't change and you wouldn't want to change.
23rd May 2019, 1:07 PM
AgentSmith
+ 3
age = 25 ^That's a variable (in math, variables have changing values) define(“AGE”, 28); ^That's a constant (they have values that do not change) However, when you're programming, you're the one that determines which are constants and which are variables, so it isn't bound to only being 28 unless you create a constant and set it to a value of 28 in its definition that you write. In the code you posted, you set it to a value of 28, which is why the constant will have a value of 28.
23rd May 2019, 1:13 PM
AgentSmith
+ 3
@Ipang Thanks. This entire thread makes a lot more sense now that I know it's being based on a quiz. :D
23rd May 2019, 3:22 PM
AgentSmith
+ 1
okay, thanx a lot for your comment)
23rd May 2019, 1:18 PM
Екатерина Рассоха
Екатерина Рассоха - avatar
18th Oct 2020, 7:24 PM
جابر جابر
جابر جابر - avatar
0
Me ayudan en C#
18th Nov 2021, 3:19 AM
Jeremías Rivas
Jeremías Rivas - avatar