How To Check The Odd And Even Number
Submitted by alpha_luna on Thursday, April 21, 2016 - 16:45.
In this article, we are going to learn on How To Check The Odd And Even Number.
This is a simple program that can really help you to determine the given number if it is Odd Number or Even Number using JavaScript. JavaScript we are going to use as our programming language. Also, I added a “Reset” button to clear the Textbox to input another number given of the user.
HTML Code
This source code where the user types the value to determine if it is Odd or Even Number.
JavaScript Code
This script will help us to determine the value if it is Odd or Even Number.
And, this is the style.
Output:
If the value is Even Number.
If the value is Odd Number.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
- <script type="text/javascript">
- function check_Even_Odd() {
- var input = document.getElementById("data_input").value;
- var number = parseInt(input);
- if (isNaN(number)) {
- alert("Please enter a number.");
- document.getElementById("data_input").value="";
- document.getElementById("result").innerHTML = "";
- document.getElementById("data_input").focus();
- }
- else if (input.length === 0) {
- alert("Please enter a valid input");
- document.getElementById("data_input").focus();
- }
- else if (number % 2 == 0 ) {
- document.getElementById("result").innerHTML = number + " <b style='color:blue; font-size:18px;'> is even number.</b>";
- }
- else {
- document.getElementById("result").innerHTML = number + " <b style='color:blue; font-size:18px;'> is odd number.</b>";
- }
- }
- function clear_textbox(){
- document.getElementById("result").innerHTML = "";
- document.getElementById("data_input").value="";
- document.getElementById("data_input").focus();
- }
- </script>
- <style type="text/css">
- body {
- font-family:Helvitica;
- color:blue;
- margin:auto;
- width:400px;
- }
- .text_input {
- font-size:18px;
- text-align:center;
- border:blue 1px solid;
- background:azure;
- width:150px;
- }
- .btn_control {
- font-size:18px;
- border:blue 1px solid;
- color:blue;
- background:skyblue;
- padding:5px;
- margin-right:20px;
- border-radius:8px;
- cursor:pointer;
- }
- .btn_control1 {
- font-size:18px;
- border:blue 1px solid;
- color:blue;
- background:white;
- border-radius:8px;
- padding:5px;
- cursor:pointer;
- }
- .text_result {
- font-size:18px;
- width:300px;
- padding:40px;
- color:red;
- border:blue 1px solid;
- background:white;
- text-align:center;
- }
- </style>


Add new comment
- 87 views