logo image

How to write Positive or Negative Number program in jQuery, HTML & javascript

229


Demo

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() {
				var number = $("#num").val();

				if (number < 0) {
					output = "Negative"
				} else {
					output = "Positive"
				}
				$("#result").html(output);
			});
		});
	</script>
</head>

<body>
	Enter a number:
	<input type="text" name="value" id="num"></input>
	<button id="btn"> Submit </button>
	<p id="result"> </p>
</body>

</html>