I would like clarification on a problem I am dealing with in JavaScript.
I designed an .html for dividing two numbers (the large number to be divided by the small number). It is a classic exercise.
With the help of JavaScript I should make this division and display the result.
I tried but it seems to fail.
Below I have the form in .html:
I tried in .js to build the solution but I can’t:
Please, if anyone has more experience, knowledge about JavaScript, some time to waste informing me, I would be grateful.
Is that the entirety of the code? Because you need to get the values when the form is submitted, so like:
const form = document.getElementById("divide");
// Listen out for the form being submitted:
form.addEventListener("submit", (event) => {
// Stop the normal behaviour of the page reloading on submit
event.preventDefault();
// DIVIDE LOGIC HERE
}
Then it’s parseInt not porseInt.
The form doesn’t need a method, you’re not submitting it to a server.
Can’t see what “result” is, but it needs to be an input for it to have a value property, and it would make more sense for it to be just a text element.