My name is Prakash and I'm new to JavaScript.
Summarize the problem.
- The goal of this program is to determine if the users integer is even or odd.
- I believe my code could be more concise.
- There is a logical error that states that the HTML Input Element is undefined.
Describe what you've tried.
- I changed the document.getElementById() to the .querySelector() and .getElementByClassName.
Show some code
https://jsfiddle.net/pherami1/jfh3xq69/2/
const input = document.getElementById('textInput');<br>
const button = document.getElementById('submitButton');<br>
button.addEventListener('click', evenOrOdd);
function evenOrOdd () {
let result;
let even;
let odd;
if (input % 2) {
result = even;
} else {
result = odd;
}
document.getElementById('para').textContent = input + " is an " + result + " number.";
}
Aucun commentaire:
Enregistrer un commentaire