Math operations

I have a question ❓ According to my course based on numbers in JavaScript //The first one let dogAge = prompt("How old is the dog") let humanAge = alert((dogAge - 2) * 4 + 21) //The second one let dogAge = prompt("How old is the dog") let humanAge = alert(dogAge - 2 * 4 + 21) Which one is correct because I gave JavaScript the first one and is giving me different answers which is not same with the second one
6 Replies
Mannix
Mannix2mo ago
this is basic math question order of operation matter 😉
Jochem
Jochem2mo ago
MDN Web Docs
Operator precedence - JavaScript | MDN
Operator precedence determines how operators are parsed concerning each other. Operators with higher precedence become the operands of operators with lower precedence.
Jochem
Jochem2mo ago
I'll link this again here
13eck
13eck2mo ago
Please use an appropriate title. “JavaScript” is vague enough to be useless
CHIDEX
CHIDEXOP2mo ago
Now I understand Tnx gee Noted boss I will use the correct title according to my question or problem Back to mathematics But JavaScript seems a little bit hard
13eck
13eck2mo ago
This isn’t a JavaScript issue, it’s maths.

Did you find this page helpful?