if, else, else if

Conditional statement to test if a condition is true of false.

 

<html>
	<head>
		<title>JavaScript</title>
	</head>
	<body>
	<script type="text/javascript">
			var a = 42;
			var b = 17;

			if (a == b){
				document.write(a + " is equal to " + b)
			} else if (a < b) {
				document.write(a + " is less than " + b)
			} else {
				document.write(a + " is more than " + b)
			}
		</script>
	</body>
</html>

Save & refresh browser:

42 is more than 17

Leave a Reply