JavaScript if statement not behaving as expected

后端 未结 4 1676
情深已故
情深已故 2021-01-26 02:33

Just learning to code JavaScript, trying to learn if statements but my code isn\'t working:

var car = 8;
if (car = 9) {
    document.write(\"your code is not wor         


        
4条回答
  •  一整个雨季
    2021-01-26 03:02

    use this code

    var car = 8;
    if (car==9)
      {
      document.write("your code is not working")
      }
    

    you need to understand about operators '=' is an assignment operator whereas '==' is a comparision operator.

    See Tutorial

提交回复
热议问题