Create an application that allows the user to enter in an integer. Your program
ID: 3758113 • Letter: C
Question
Create an application that allows the user to enter in an integer. Your program will then compute whether or not the number entered is even or odd.
Input Validation: This program must check to see if what the user entered is a valid integer. If it is not, an error message should be displayed.
Sample Runs:
This application Needs to have a working Clear button. Once clicked, this button will clear the contents of the textbox and the label used to display the result. This application also needs to have a working Exit button. Once clicked, this button will close the application. Your application needs to look like the Sample Run figures from the previous page.
Even or Odd Input an Integer You need to enter a valid integer. Compute Clear ExitExplanation / Answer
<html>
<head>
<script type="text/javascript">
var n=prompt("Input an Integer");
n = parseInt(n); // Interger conversion
if (isNaN(n)) //checking whether it is number or not
{
alert("Please Enter a Number"); // alerts for given number
}
else if (n == 0) //condition checking
{
alert("Given number is zero"); // alert
}
else if (n%2) //even number condition checking
{
alert("This number is odd"); // an alert
}
else
{
alert("This number is even"); // even number
}
</script>
</head>
<body>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.