0
Someone explain me why JavaScript calculating like this 😭
Someone tell me why the answer of brain and calculator is different than JavaScript calculated answer for the given code!.... . var a = 7 a = a-6 console.log(3*(a-5)+12) . JavaScript answer : 0 ; . But how n why ???
12 Réponses
+ 9
a = 7
a = 7-6 = 1
(3*(1-5)+12)
(3*(-4)+12)
((-12)+12) = 0
+ 6
If you are unsure how the code works or what the calculation does, you can print out the steps with console.log().
Good night ;)
+ 3
From your profile it looks like you completed the Javascript course... Did you try to run this code and print the intermediate steps?
7 – 6 = 1
3*(1–5) + 12= 3*(-4) + 12 = 0
Yaroslav Vernigora thanks, edited!
+ 1
its okay, thats what the community is for. all of us are once wrong. even Lisa messed up a little with the answer. it can affect later time. its about half past one in the night on my watch. I think that Germany has something like that...
+ 1
I would advise you to repeat the topic priority of performing operators
+ 1
a = 7- 6 = 1
[3*(1-5) + 12]
You solve inner bracket first i.e ()
[3*(-4) + 12]
Then multiplication
[-12 + 12]
0
It is correct check on Bodmas rule
Bracket
Of
Division
Multiplication
Addition
Substraction
0
Lisa m actually weak in maths as it's not a part of my studies as well for years ago 💀... M good at javascript + jQuery + react (in progress). But not good in math questions 🌚🌚🌚🌚🌚🌚 feeling so dumb after getting the answer 🤣
0
Visualize your code execution
(Python, Java, C, C++, JavaScript, Ruby)
https://pythontutor.com
This coding tutor tool helps you learn Python, JavaScript, C, C++, and Java by visualizing code execution. You can use it to debug your homework assignments and as a supplement to online coding tutorials.
0
Mirielle no I were confused in brackets, I were adding all the values first which is equal to 8 than multiply, that's why.
0
a = 7
a = 7-6 = 1
For console. Log....
(3*(1-5)+12)
(3*(-4)+12)
((-12)+12) = 0