+ 2
Why the code is being executed even the condition is not true?
https://code.sololearn.com/WeQKTq5wO457/?ref=app var batteryLevel = 10 var batteryLevel = 90 if (batteryLevel = 100){ alert ("Battery is full") }
4 ответов
+ 4
because u have assigned 100 to battery value.. and it is not comparing it.. u need to use == operator
+ 1
Why is that not considered as a condition instead of assigning a new value ?
@Sami Khan
+ 1
because that was an assignment operator.. This is " ==" the comparison operator
+ 1
@Sami Khan Thank you!
Now I got it. The assignment operator will assign a value and won't evaluate or compare two things to make the condition. We need something that would make a condition not a decision :)