HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line HTML Plain Text HTML Popup Hspace in HTML HTML Interpreter HTML Maker HTML Nav Tag HTML Nested List How to create cards in HTML HTML Writer OnKeyDown in HTML Onmove in HTML Strip HTML Tags from String Style Dark Mode in HTML Automatic Image Slider in HTML CSS Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line HTML Section Tag hspace and vspace in Html HTML and CSS Landing Page HTML Row Span HTML Simulator How to give Space in HTML How to Display Text using HTML HTML to TEXT Converter HTML Video Poster Link CSS to HTML Nested List Example Nowrap in HTML script Tag in HTML section Tag in HTML select in HTML

Addition of two numbers in JavaScript using HTML

What is JavaScript?

JavaScript is a programming language that is primarily used to create interactive and dynamic websites. It is a high-level, dynamic, interpreted language that is designed to be lightweight and easy to learn. JavaScript code can be embedded in HTML pages, and it is executed by web browsers on the client-side to enhance the user experience of web applications.

JavaScript can be used for a variety of tasks, including creating dynamic web page content, validating forms, handling events, and building interactive user interfaces. It is also used on the server-side with Node.js to build server-side applications.

JavaScript is a versatile language that supports many programming paradigms, including procedural, functional, and object-oriented programming. It has a vast and active developer community, which has resulted in a rich ecosystem of libraries and frameworks that can be used to simplify and accelerate the development of web applications.

Some popular JavaScript frameworks and libraries include React, Angular, Vue.js, jQuery, and Node.js. Additionally, JavaScript has evolved significantly over the years, and the latest version, ECMAScript 2021 (ES2021), includes many new features and improvements that make it an even more powerful and efficient language.

Example:

Here, an example how to add two number using HTML in JavaScript:

Create an HTML file with a form containing two input fields for the user to enter the numbers to add and a button to trigger the addition:

<!DOCTYPE html>
<html>
<head>
	<title>Addition Program</title>
</head>
<body>
	<form>
		<label for="num1">Enter First Number:</label>
		<input type="number" id="num1" name="num1"><br><br>
		<label for="num2">Enter Second Number:</label>
		<input type="number" id="num2" name="num2"><br><br>
		<input type="button" value="Add" onclick="addNumbers()">
	</form>


	<script src="script.js"></script>
</body>
</html>

Output:

Addition of two numbers in JavaScript using HTML

In this code, we have created a form with two input fields of type "number" to take input from the user. The submit button has an onclick event that calls a JavaScript function "addNumbers()" to add the two numbers.

Create a JavaScript file named "script.js" and add the following code:

functionaddNumbers() {
  // Get the input values from the user
var num1 = document.getElementById("num1").value;
var num2 = document.getElementById("num2").value;


  // Convert the input values to numbers and add them
var result = Number(num1) + Number(num2);


  // Display the result
alert("The sum of " + num1 + " and " + num2 + " is " + result);
}

In this code, we have created a function "addNumbers()" that gets the values entered by the user using the "getElementById()" method and stores them in variables "num1" and "num2". Then, we convert these two variables to numbers using the "Number()" function and add them using the "+" operator. Finally, we use the "alert()" method to display the result to the user.

Save the "script.js" file and open the HTML file in a web browser. Enter two numbers in the input fields and click the "Add" button. The function "addNumbers()" will be called, and the sum of the two numbers will be displayed in an alert message.

Output:

Addition of two numbers in JavaScript using HTML

Advantage of using JavaScript

JavaScript offers several advantages that make it a popular choice for web development.

Here are some of the main advantages of using JavaScript:

  • Client-side scripting: JavaScript is a client-side scripting language, which means it is executed by the user's web browser. This allows web developers to create dynamic and interactive web pages that respond to user actions in real-time without having to rely on server-side processing.
  • Wide adoption: JavaScript is one of the most widely used programming languages in the world. It is supported by all major web browsers and has a massive developer community. This means that there are many libraries, frameworks, and tools available for JavaScript that can make web development faster and easier.
  • Easy to learn: JavaScript is a relatively easy language to learn, especially for those who are already familiar with HTML and CSS. It has a simple syntax and is forgiving of errors, which makes it an ideal language for beginners.
  • Versatile: JavaScript is a versatile language that can be used for a wide range of tasks. It can be used to create everything from simple animations and form validations to complex web applications and games.
  • Fast and responsive: JavaScript code executes quickly in the user's web browser, which means that web pages built with JavaScript are fast and responsive. This is particularly important for web applications that require real-time data processing and interactivity.


















⚙️