Knowee
Questions
Features
Study Tools
\n\n\n\n```\n\nJavaScript (script.js):\n```javascript\nfunction checkNumber() {\n var num = document.getElementById(\"numInput\").value;\n if (num % 2 == 0) {\n document.getElementById(\"result\").innerHTML = num + \" is an even number.\";\n } else {\n document.getElementById(\"result\").innerHTML = num + \" is an odd number.\";\n }\n}\n```\n\nIn this program, the user enters a number in the input field and clicks the \"Submit\" button. The `checkNumber` function is then called, which gets the value of the input field and checks if it is divisible by 2 (i.e., it is even). If it is, it prints that the number is even; otherwise, it prints that the number is odd.","text":"Sure, here is a simple HTML and JavaScript program that accepts a number as input and prints whether the number is odd or even.\n\nHTML:\n```html\n\n\n\n\n

Check if a number is odd or even

\n\n

Enter a number:

\n\n\n\n\n\n

\n\n\n\n\n\n```\n\nJavaScript (script.js):\n```javascript\nfunction checkNumber() {\n var num = document.getElementById(\"numInput\").value;\n if (num % 2 == 0) {\n document.getElementById(\"result\").innerHTML = num + \" is an even number.\";\n } else {\n document.getElementById(\"result\").innerHTML = num + \" is an odd number.\";\n }\n}\n```\n\nIn this program, the user enters a number in the input field and clicks the \"Submit\" button. The `checkNumber` function is then called, which gets the value of the input field and checks if it is divisible by 2 (i.e., it is even). If it is, it prints that the number is even; otherwise, it prints that the number is odd.","author":{"@type":"Person","name":"Anonymous"},"answerCount":1,"datePublished":"2024-08-13T15:29:30.144581","acceptedAnswer":{"@type":"Answer","author":{"@type":"Organization","name":"Knowee AI"},"upvoteCount":0,"text":"Sure, here is a simple HTML and JavaScript program that accepts a number as input and prints whether the number is odd or even.\n\nHTML:\n```html\n\n\n\n\n

Check if a number is odd or even

\n\n

Enter a number:

\n\n\n\n\n\n

\n\n\n\n\n\n```\n\nJavaScript (script.js):\n```javascript\nfunction checkNumber() {\n var num = document.getElementById(\"numInput\").value;\n if (num % 2 == 0) {\n document.getElementById(\"result\").innerHTML = num + \" is an even number.\";\n } else {\n document.getElementById(\"result\").innerHTML = num + \" is an odd number.\";\n }\n}\n```\n\nIn this program, the user enters a number in the input field and clicks the \"Submit\" button. The `checkNumber` function is then called, which gets the value of the input field and checks if it is divisible by 2 (i.e., it is even). If it is, it prints that the number is even; otherwise, it prints that the number is odd.","url":"https://studygpt.app/questions/72182710-write-an-html-and-javascript-program-which-accepts-n-as-input-and","datePublished":"2024-08-13T15:29:30.144581"}}}

Write an HTML and JavaScript program which accepts N as input and print N is oddor even number

Question

Write an HTML and JavaScript program which accepts N as input and print N is oddor even number

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple HTML and JavaScript program that accepts a number as input and prints whether the number is odd or even.

HTML:

<!DOCTYPE html>
<html>
<body>

<h2>Check if a number is odd or even</h2>

<p>Enter a number:</p>

<input id="numInput">

<button onclick="checkNumber()">Submit</button>

<p id="result"></p>

<script src="script.js"></script>

</body>
</html>

JavaScript (script.js):

function checkNumber() {
    var num = document.getElementById("numInput").value;
    if (num % 2 == 0) {
        document.getElementById("result").innerHTML = num + " is an even number.";
    } else {
        document.getElementById("result").innerHTML = num + " is an odd number.";
    }
}

In this program, the user enters a number in the input field and clicks the "Submit" button. The checkNumber function is then called, which gets the value of the input field and checks if it is divisible by 2 (i.e., it is even). If it is, it prints that the number is even; otherwise, it prints that the number is odd.

This problem has been solved

Similar Questions

Write an HTML and JavaScript program which accepts N as input and print first Nodd numbers

Write a program to print only the even numbers till given NInput FormatA single integer 'N'Output FormatDisplay all the even numbers between 0 and NSample Input10Sample Output0 2 4 6 8 10

Program to ask a user for supplying n different integers and countthe total number of even and odd values among them

Complete the function count_odd_even() , which receives number of elements and array as input. Function should count number of even numbers and odd numbers in the array and print it.Input Format:No Need to read any input, as it is predefined.Output Format:Print the count of odd and even as: Odd = ODD_COUNTEven = EVEN_COUNTConstraints:1<=size<=10^9 1<=arr[ind]<=10^15Sample Input 1:1047 41 87 88 95 46 35 66 63 93Sample Output 1:Odd = 7Even = 3Sample Input 2:81 2 3 4 5 6 7 8Sample Output 2:Odd = 4Even = 4

For some integer n, the odd integer is represented in the form of:

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.