00:01
In this question, we have to use a basic html to write a code.
00:07
So, we have a simple html form with two input fields that are there for entering the numbers.
00:16
So, we are going to write this in html editor and we have two input text input fields.
00:26
We'll have in your text input fields.
00:35
So, one will be for entering the number for entering the number that is there and second one will be for of the four buttons for different operations.
00:59
That is the four buttons for different operations.
01:18
So, these operations are add, subtract, then multiply, divide as you know like this.
01:42
So, the calculate function in this case, it is used when or it is called when a button is clicked.
01:52
So, the calculate function here will be used when the button is clicked.
02:01
So, let us see how we will proceed to write a code in html.
02:06
So, we'll just use a basic compiler to show how this is done.
02:09
So, first thing we will just write a basic html structure that includes the script.
02:18
So, this is our basic body that we will be using.
02:23
So, here the script tag inside the head section that we see.
02:28
So, this is where our code will be placed.
02:32
So, the calculator form and elements will be placed within the body over here.
02:38
So, let us look at the code.
02:42
So, the javascript code that is asked to us in the question.
02:47
So, here firstly we will display a function class that is there.
02:54
So, a calculate function is declared which will be called when a button is clicked.
03:01
So, it takes an operator operation parameter to determine which operation should be performed that is add, subtract, multiply or divide.
03:13
So, now we need to have some input retrieval.
03:17
So, for that we will be using these two retrieve lines that are there like this.
03:25
So, here these lines retrieve the values entered in the input fields with the ids number 1 and num2 and convert them to integers using the parts int .document .getelementbyid.
03:41
So, this is used to access the dom elements by their ids.
03:46
Now, we will see at the input validation.
03:49
So, if for this we will be using and if loop with the and we will return the values in the end.
03:58
So, here as you can see these lines check for the input validation.
04:02
So, the first condition here it checks if either number 1 or number 2 is nan that means not a number.
04:13
Here nan means not a number...