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 ???

19th Aug 2022, 10:02 PM
Syed Shayan
Syed Shayan - avatar
12 Answers
+ 9
a = 7 a = 7-6 = 1 (3*(1-5)+12) (3*(-4)+12) ((-12)+12) = 0
19th Aug 2022, 10:08 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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 ;)
19th Aug 2022, 10:26 PM
Lisa
Lisa - avatar
+ 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!
19th Aug 2022, 10:11 PM
Lisa
Lisa - avatar
+ 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...
19th Aug 2022, 10:24 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I would advise you to repeat the topic priority of performing operators
19th Aug 2022, 10:33 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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
21st Aug 2022, 9:56 AM
Urhomovo Collins Rume
Urhomovo Collins Rume - avatar
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 🤣
19th Aug 2022, 10:20 PM
Syed Shayan
Syed Shayan - avatar
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.
19th Aug 2022, 10:37 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
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.
20th Aug 2022, 5:33 AM
Syed Shayan
Syed Shayan - avatar
0
a = 7 a = 7-6 = 1 For console. Log.... (3*(1-5)+12) (3*(-4)+12) ((-12)+12) = 0
20th Aug 2022, 2:08 PM
Jay Mukherjee
Jay Mukherjee - avatar