{"id":1988,"date":"2017-07-14T03:27:46","date_gmt":"2017-07-14T03:27:46","guid":{"rendered":"http:\/\/javascript-tutor.net\/?page_id=1988"},"modified":"2017-07-14T03:45:18","modified_gmt":"2017-07-14T03:45:18","slug":"pythagoras-theorem","status":"publish","type":"page","link":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/","title":{"rendered":"Pythagoras  Theorem"},"content":{"rendered":"<p>Pythagoras Theorem is used to solve problems related to the length of the sides of a triangle.<br \/>\nThe formula to \u00a0is<\/p>\n<p><strong>AB<sup>2<\/sup>+AC<sup>2<\/sup>=BC<sup>2<\/sup><\/strong><\/p>\n<p>AB \u00a0is the opposite side, AC is the adjacent and BC is the hypotenuse\u00a0of a triangle ABC.<\/p>\n<p>We shall create a JavaScript application to deal with problems related to\u00a0Pythagoras Theorem. In this application, we shall insert two input boxes\u00a0for the user to key in the length of the opposite side and the length of the adjacent side. The user can then click on the Calculate Hypotenuse button to find the answer.<\/p>\n<p>The JavaScript is as follows:<\/p>\n<pre>function Calhypo(a,b){\r\nvar hypo=Math.sqrt(Math.pow(a,2)+Math.pow(b,2));\r\nreturn hypo;\r\n}\r\nfunction Cal_hypo(){\r\nvar  x=parseInt(document.getElementById(\"adjacent\").innerHTML);\r\nvar  y=parseInt(document.getElementById(\"opposite\").innerHTML);\r\nvar z=Calhypo(x,y);\r\nvar c=z.toFixed(2);\r\ndocument.getElementById('ans').textContent=\"The Length of hypotenuse is= \"+c;\r\n\r\n}\r\n<\/pre>\n<p>We use the Math function pow(n,2) to find the square of a and b. The sqrt function is to find the square root of a number. We use the toFixed function to convert the resulting answer into 2 decimal places.<\/p>\n<p>The HTML script is as follows:<\/p>\n<pre>&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta http-equiv=\"Content-Type\" content=\"text\/html; charset=windows-1252\"&gt;\r\n&lt;title&gt;Pythagoras Theorem&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body onload=\"RandomFn()\"&gt;\r\n&lt;h1&gt;Pythagoras Theorem&lt;\/h1&gt;\r\n&lt;p&gt;Length of adjacent side a=&lt;b id=\"adjacent\"&gt;&lt;\/b&gt;&lt;\/p&gt;\r\n&lt;p&gt;Length of opposite side b=&lt;b id=\"opposite\"&gt;&lt;\/b&gt;&lt;\/p&gt;\r\n\r\n&lt;P id=\"ans\"&gt;The Length of hypotenuse c is&lt;\/p&gt;\r\n&lt;input type=\"button\" value=\"Calculate hypotenuse\" onclick=\"Cal_hypo()\"&gt;&lt;br&gt;&lt;br&gt;\r\n&lt;input type=\"button\" value=\"Next Question\" onclick=\" location.reload();\"&gt;\r\n&lt;script&gt;\r\nfunction RandomFn() {\r\n document.getElementById(\"adjacent\").innerHTML = parseInt(Math.random()*9+1);\r\n document.getElementById(\"opposite\").innerHTML = parseInt(Math.random()*9+1);\r\n \r\n }\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\" src=\"pythagoras1.js\"&gt;&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>Click on<a href=\"http:\/\/javascript-tutor.net\/jSample\/pythagoras1.html\"> Pythagoras Theorem<\/a> to view the output.<\/p>\n<p>&nbsp;<\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- Javascript Responsive Ads --><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"9005101105\"\n     data-ad-format=\"auto\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pythagoras Theorem is used to solve problems related to the length of the sides of a triangle. The formula to \u00a0is AB2+AC2=BC2 AB \u00a0is the opposite side, AC is the adjacent and BC is the hypotenuse\u00a0of a triangle ABC. We shall create a JavaScript application to deal with problems related to\u00a0Pythagoras Theorem. In this application, &hellip; <a href=\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Pythagoras  Theorem&#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-1988","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>Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"og:description\" content=\"Pythagoras Theorem is used to solve problems related to the length of the sides of a triangle. The formula to \u00a0is AB2+AC2=BC2 AB \u00a0is the opposite side, AC is the adjacent and BC is the hypotenuse\u00a0of a triangle ABC. We shall create a JavaScript application to deal with problems related to\u00a0Pythagoras Theorem. In this application, &hellip; Continue reading &quot;Pythagoras Theorem&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript Online | Free Interactive JavaScript Tutorials\" \/>\n<meta property=\"article:modified_time\" content=\"2017-07-14T03:45:18+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\",\"url\":\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\",\"name\":\"Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/javascript-tutor.net\/#website\"},\"datePublished\":\"2017-07-14T03:27:46+00:00\",\"dateModified\":\"2017-07-14T03:45:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/javascript-tutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pythagoras Theorem\"}]},{\"@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":"Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials","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":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/","og_locale":"en_US","og_type":"article","og_title":"Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials","og_description":"Pythagoras Theorem is used to solve problems related to the length of the sides of a triangle. The formula to \u00a0is AB2+AC2=BC2 AB \u00a0is the opposite side, AC is the adjacent and BC is the hypotenuse\u00a0of a triangle ABC. We shall create a JavaScript application to deal with problems related to\u00a0Pythagoras Theorem. In this application, &hellip; Continue reading \"Pythagoras Theorem\"","og_url":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/","og_site_name":"Learn JavaScript Online | Free Interactive JavaScript Tutorials","article_modified_time":"2017-07-14T03:45:18+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/","url":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/","name":"Pythagoras Theorem - Learn JavaScript Online | Free Interactive JavaScript Tutorials","isPartOf":{"@id":"https:\/\/javascript-tutor.net\/#website"},"datePublished":"2017-07-14T03:27:46+00:00","dateModified":"2017-07-14T03:45:18+00:00","breadcrumb":{"@id":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/javascript-tutor.net\/index.php\/pythagoras-theorem\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/javascript-tutor.net\/"},{"@type":"ListItem","position":2,"name":"Pythagoras Theorem"}]},{"@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\/1988","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=1988"}],"version-history":[{"count":7,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1988\/revisions"}],"predecessor-version":[{"id":1995,"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1988\/revisions\/1995"}],"wp:attachment":[{"href":"https:\/\/javascript-tutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}