Javascript Error Prevention

Hi,

Started to do html. Stuck on the following query.

Giving the following code, add in any necessary error prevention and warnings
In particular make sure inputs are numbers, make sure user cannot divide by
zero

HTML

<label> Add a number </label>
<input id="numberOne"></input>
<label> Add a number </label>
<input id="numberTwo"></input>
<button onclick="divide()">divide</button>
<button onclick="multiply()">multiply</button>

Javascript

function divide()
{
var one = document.getElementById("numberOne").value;
var two = document.getElementById("numberTwo").value;
var sum = one/two;
document.getElementById("result").innerHTML =sum;
}

function multiply()
{
var one =document.getElementById("numberOne").value;
var two = document.getElementById("numberTwo").value;
var sum = one* two;
document.getElementById("result").innerHTML =sum;
}

Could someone explain the step by step process of each error prevention. I’m completely at a loss here, even google doesn’t make sense as I don’t understand the task.

Also this please.

<label> Add a number </label>
<input id="numberOne"></input>
<label> Add a number </label>
<input id="numberTwo"></input>
<button onclick="divide()">divide</button>
<button onclick="multiply()">multiply</button>

as this is an html lesson for what you said, I imagine it is about attributes for the input element

have you already seen some of those?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.