Paul Paul - 3 months ago 8
Javascript Question

elementary If else statement not working in javascript

I am totally new to javaScript and cannot understand why this elementary if else statement won't work. And before you mark down yes I have looked and can't find a simple answer to this simple question. Many thanks.

$(document).ready(function (){

var try = 0;

if (try == 0){

alert("yes");

} else {

alert("no");

}

});

Answer

Because try is a javascript keyword and you cannot use it.

Change it to try1 just for instance.

$(document).ready(function (){

            var try1 = 0;

            if (try1 == 0){

                alert("yes");

            } else {

                alert("no");

            }

        });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>