jeudi 3 décembre 2020

Alternative Document Method

My name is Prakash and I'm new to JavaScript.

Summarize the problem.

  1. The goal of this program is to determine if the users integer is even or odd.
  2. I believe my code could be more concise.
  3. There is a logical error that states that the HTML Input Element is undefined.

Describe what you've tried.

  1. 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