Code:

var a = 0; prompt("Введите свой возраст ниже",a); if (a<18) { alert("Вам сюда нельзя!"); } else { alert("Добро пожаловать!"); } 

For some reason, the condition is always satisfied, if we declare a variable and, without assigning a value, it works normally. Why?

    1 answer 1

    prompt - takes 2 arguments, 1st line with message, 2nd default value

    In your case, your entered data is not recorded anywhere. and it turns out that a always = 0

     var a = prompt("Введите свой возраст ниже"); if (a<18) {alert("Вам сюда нельзя!");} else {alert("Добро пожаловать!");} 

    • one
      You should also bring to the number - Alexey Ten
    • @AlexeyTen, that was not the problem. Add. checks can always be done. - meine