{"id":281,"date":"2011-12-06T23:07:25","date_gmt":"2011-12-06T23:07:25","guid":{"rendered":"http:\/\/javascript-tutor.net\/index.php\/"},"modified":"2017-11-18T05:40:47","modified_gmt":"2017-11-18T05:40:47","slug":"lesson-5-arithmetic-operations-javascript","status":"publish","type":"page","link":"https:\/\/javascript-tutor.net\/index.php\/lesson-5-arithmetic-operations-javascript\/","title":{"rendered":"JavaScript Lesson 5: Arithmetic Operations in JavaScript"},"content":{"rendered":"<ul>\n<li>\n<h4 align=\"center\"><a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-4-variables-javascript\/\">&lt;Lesson 5&gt;<\/a> <a href=\"http:\/\/javascript-tutor.net\/index.php\/tutorial\/\">[Contents]<\/a> <a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-6-comparison-logical-operators\/\">&lt;Lesson 6&gt;<\/a><\/h4>\n<h3><strong>5.1 Arithmetic Operations in JavaScript<\/strong><\/h3>\n<p>JavaScript is not just a scripting language, it can also perform arithmetic operations. On top of that, it can interact with online users by receiving data from them, operate on the data and then display the output to the users. The four basic arithmetic operators in JavaScript are shown in the following table:<\/p>\n<table style=\"table-layout: fixed; width: 70%; font-size: 100%; overflow-x: auto;\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n<tbody>\n<tr>\n<th width=\"176\">Operation<\/th>\n<th style=\"text-align: center;\"><strong>Operator<\/strong><\/th>\n<\/tr>\n<tr>\n<td width=\"176\">Addition<\/td>\n<td style=\"text-align: center;\"><strong>+<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"176\">Subtraction<\/td>\n<td style=\"text-align: center;\"><strong>&#8211;<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"176\">Multiplication<\/td>\n<td style=\"text-align: center;\"><strong>*<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"176\">Division<\/td>\n<td style=\"text-align: center;\"><strong>\/<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Let us construct our first arithmetic program in JavaScript. You can either use a text editor such as notepad to type in the statements. You can also use Microsoft Frontpage or Dreamweaver to do the job. However, the best free editor I would recommend is Notepad++, which you can download from <a href=\"https:\/\/notepad-plus-plus.org\/\">\u00a0https:\/\/notepad-plus-plus.org\/<\/a> .<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"5669011038\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p>Now, key\u00a0in the following lines of statements.<\/p>\n<pre style=\"font-size: 110%;\">&lt;HTML&gt;&lt;HEAD&gt;\r\n&lt;Script Language=\"JavaScript\"&gt;\r\nvar\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Number1,\u00a0\/\/ this is the first string input by the user\r\nNumber2 ,\u00a0\/\/ this is the second string input by the user\r\nNum1 ,\u00a0\/\/ numeric value converted from Number1\r\nNum2, \/\/ numeric value converted from Number2\r\nsum,\r\ndifference ,\r\nproduct,\r\nquotient;\r\nNumber1=window.prompt(\"Enter your first Integer\",\"0\");\r\nNumber2=window.prompt(\"Enter your second integer\",\"0\");\r\nNum1=parseInt(Number1);\r\nNum2=parseInt(Number2);\r\nsum=Num1+Num2;\r\ndifference=Num1-Num2;\r\nproduct=Num1*Num2;\r\nquotient=Num1\/Num2;\r\ndocument.writeln(Number1+\"+\"+Number2+\"=\"+sum+\"&lt;BR&gt;\");\r\ndocument.writeln(Number1+\"-\"+Number2+\"=\"+difference+\"&lt;BR&gt;\");\r\ndocument.writeln(Number1+\"x\"+Number2+\"=\"+product+\"&lt;BR&gt;\");\r\ndocument.writeln(Number1+\"\/\"+Number2+\"=\"+quotient);&lt;\/Script&gt;\r\n\r\n<\/pre>\n<p>Click\u00a0<a href=\"http:\/\/javascript-tutor.net\/java_tutor\/java_sample1.htm\">Testing Page<\/a> to view the output<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"2916349441\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 align=\"center\"><a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-4-variables-javascript\/\">&lt;Lesson 4&gt;<\/a> <a href=\"http:\/\/javascript-tutor.net\/index.php\/tutorial\/\">[Contents]<\/a> <a href=\"http:\/\/javascript-tutor.net\/index.php\/lesson-6-comparison-logical-operators\/\">&lt;Lesson 6&gt;<\/a><\/h4>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>&lt;Lesson 5&gt; [Contents] &lt;Lesson 6&gt; 5.1 Arithmetic Operations in JavaScript JavaScript is not just a scripting language, it can also perform arithmetic operations. On top of that, it can interact with online users by receiving data from them, operate on the data and then display the output to the users. The four basic arithmetic operators &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/lesson-5-arithmetic-operations-javascript\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;JavaScript Lesson 5: Arithmetic Operations in JavaScript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":35895,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-281","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Arithmetic Operations in JavaScript<\/title>\n<meta name=\"description\" content=\"This javascript lesson shows how to perform arithmetic operations in javascript\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arithmetic Operations in JavaScript\" \/>\n<meta property=\"og:description\" content=\"This javascript lesson shows how to perform arithmetic operations in javascript\" \/>\n<meta property=\"og:url\" content=\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-18T05:40:47+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/lesson-5-arithmetic-operations-javascript\/\",\"url\":\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html\",\"name\":\"Arithmetic Operations in JavaScript\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2011-12-06T23:07:25+00:00\",\"dateModified\":\"2017-11-18T05:40:47+00:00\",\"description\":\"This javascript lesson shows how to perform arithmetic operations in javascript\",\"breadcrumb\":{\"@id\":\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Lesson 5: Arithmetic Operations in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/javascript-tutor.net\/#website\",\"url\":\"https:\/\/javascript-tutor.net\/\",\"name\":\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"description\":\"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Arithmetic Operations in JavaScript","description":"This javascript lesson shows how to perform arithmetic operations in javascript","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html","og_locale":"en_US","og_type":"article","og_title":"Arithmetic Operations in JavaScript","og_description":"This javascript lesson shows how to perform arithmetic operations in javascript","og_url":"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_modified_time":"2017-11-18T05:40:47+00:00","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/lesson-5-arithmetic-operations-javascript\/","url":"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html","name":"Arithmetic Operations in JavaScript","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2011-12-06T23:07:25+00:00","dateModified":"2017-11-18T05:40:47+00:00","description":"This javascript lesson shows how to perform arithmetic operations in javascript","breadcrumb":{"@id":"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/javascript-tutor.net\/jstutor\/jstutor_lesson5.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"JavaScript Lesson 5: Arithmetic Operations in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/javascript-tutor.net\/#website","url":"https:\/\/javascript-tutor.net\/","name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","description":"Master JavaScript with free, interactive tutorials for beginners and experienced coders. Practice live coding and visualize how JavaScript works step by step.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/users\/35895"}],"replies":[{"embeddable":true,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":35,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/281\/revisions"}],"predecessor-version":[{"id":2266,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/281\/revisions\/2266"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}