Write a program to check whether the last digit of a number is divisible by 3 or not using html css javascript

here's an example of an HTML, CSS, and JavaScript program that checks whether the last digit of a number entered by the user is divisible by 3 or not:


html
<!DOCTYPE html>
<html>
	<head>
		<style>
			body {
				font-family: Arial, sans-serif;
			}
			.container {
				width: 300px;
				margin: 0 auto;
				text-align: center;
				padding: 20px;
				border: 1px solid #ccc;
				border-radius: 5px;
				background-color: #f7f7f7;
			}
		</style>
	</head>
	<body>

		<div class="container">
			<h2>Last Digit Divisibility Checker</h2>
			<label for="number">Enter a number:</label>
			<input type="number" id="number">
			<button onclick="checkDivisibility()">Check</button>
			<p id="result"></p>
		</div>

		<script>
			function checkDivisibility() {
				var numberInput = document.getElementById('number');
				var resultElement = document.getElementById('result');

				var number = parseInt(numberInput.value);
				if (isNaN(number)) {
					resultElement.innerText = 'Please enter a valid number.';
					return;
				}

				var lastDigit = number % 10;
				if (lastDigit % 3 === 0) {
					resultElement.innerText = 'The last digit is divisible by 3.';
				} else {
					resultElement.innerText = 'The last digit is not divisible by 3.';
				}
			}
		</script>

	</body>
</html>

This program creates a simple web page with an input field for the user to enter a number, a "Check" button to trigger the calculation, and a paragraph element to display the result. The JavaScript function `checkDivisibility()` is called when the button is clicked. It extracts the last digit of the entered number using the modulo operator `%` and then checks whether it's divisible by 3. The result is displayed on the webpage accordingly.


Output:
img

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 Previous