sample exam questions and answers with javascript 2 - sum of two numbers

Опубликовано: 08 Сентябрь 2026
на канале: Ergun Karakus
288
11

sum of 2 numbers with javascript, js course exam questions, web design course exam questions,
web design course 2nd semester exam questions,

Hello dear followers, I am your training coach produced with Artificial Intelligence, in this video we will continue to solve simple problems in Javascript with you.

Simple solutions with js, solutions to exam questions; In this video of our video series, we will write the codes that find the sum of 2 numbers.

In this example we will use text boxes to get information from the user.

First of all, we open a new html document and start coding.
We will need 2 text boxes for data entries, a div element for the result, and a button to trigger the result finding process.
We add a text box with id number1 to enter the first number.
Likewise, we add another text box with id number2 to enter the second number.
We are adding a div structure where we will write the sum of the numbers entered in the two text boxes, and the ID of this div element will be the result.
We add a button that will trigger the result finding process.
After coding the HTML structure, we will start writing the javascript codes.
For this, we first open the script tags.
we get our button as button1.
We define the button click event as a function.
in this function we obtain the values of the text boxes respectively.
Since addition is an arithmetic operation, the values we get must be numeric, that is, Number type.
We convert the incoming values into numerical values by writing Number at the beginning of the values we receive.
We define the sum variable that will store the sum of the two numbers and equate the sum of the value from the text boxes to this variable.
We obtain the div element and send its total value to the innerHTML property of this element.

That's it ,
Now we are testing our code.

After coding the work, I recommend you to develop at the points I will count.
ensuring that the values from the text boxes are numbers,
Finding the sum of 3 numbers,
Finding the average of 2 numbers,
Defining the sum function to find the result of the addition operation,
get values with prompt,
write the result with alert,
adding bootstrap styles to the work.
You can add to these enhancement points.


To write a result, use a text box instead of a div, and please write in the comments below the video which property you need to add so that the values in it are not changed by the user.

REMEMBER, I look forward to your comments.

In the meantime, you can press the like button and subscribe to support and contribute to the coming of the videos. See you in the next video.