javascript if conditions sample program


Demo

<iframe height='265' scrolling='no' title='rzwZmJ' src='//codepen.io/fastfoodcoding/embed/rzwZmJ/?height=265&theme-id=light&default-tab=html,result&embed-version=2' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'>See the Pen <a href='https://codepen.io/fastfoodcoding/pen/rzwZmJ/'>rzwZmJ</a> by fastfoodcoding (<a href='https://codepen.io/fastfoodcoding'>@fastfoodcoding</a>) on <a href='https://codepen.io'>CodePen</a>. </iframe>

Code

<html>

<head>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
	<script>
		$(document).ready(function() {
			$("#btn").click(function() {
				console.log("after click the button");
				var age = $("#age").val();
				console.log("selct age is" + age);

				if (age < 0) {
					$("#result").html("check your age");
					return;
				}
				var output = '';

				if (age >= 0 && age < 10) {
					output = 'infant'
				} else if (age >= 11 && age <= 17) {
					output = 'minor'
				} else if (age >= 18 && age <= 50) {
					output = 'major'
				} else {
					output = 'adult'
				}
				$("#result").html(output);
			});
		});
	</script>
</head>

<body>
	Enter age :
	<input type="text" name="number" id="age"> </input><br><br>
	<button id="btn"> Submit </button>
	<p id="result"></p>
</body>

</html>