{"id":1739,"date":"2024-12-27T16:47:10","date_gmt":"2024-12-27T16:47:10","guid":{"rendered":"https:\/\/donhit.com\/en\/?p=1739"},"modified":"2025-02-07T08:05:17","modified_gmt":"2025-02-07T08:05:17","slug":"quadratic-formula","status":"publish","type":"post","link":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/","title":{"rendered":"Quadratic Formula Calculator"},"content":{"rendered":"<p><center>    <div class=\"calculator\">\r\n        <h2 class=\"title\">Quadratic Formula Calculator<\/h2>\r\n        <p class=\"equation\">ax\u00b2 + bx + c = 0<\/p>\r\n        \r\n        <div class=\"input-group\">\r\n            <label for=\"a\">Enter a:<\/label>\r\n            <input type=\"number\" id=\"a\" placeholder=\"Enter coefficient a\" step=\"any\" required>\r\n            <span class=\"error\" id=\"error-a\">Please enter a valid number (a \u2260 0)<\/span>\r\n        <\/div>\r\n\r\n        <div class=\"input-group\">\r\n            <label for=\"b\">Enter b:<\/label>\r\n            <input type=\"number\" id=\"b\" placeholder=\"Enter coefficient b\" step=\"any\" required>\r\n            <span class=\"error\" id=\"error-b\">Please enter a valid number<\/span>\r\n        <\/div>\r\n\r\n        <div class=\"input-group\">\r\n            <label for=\"c\">Enter c:<\/label>\r\n            <input type=\"number\" id=\"c\" placeholder=\"Enter coefficient c\" step=\"any\" required>\r\n            <span class=\"error\" id=\"error-c\">Please enter a valid number<\/span>\r\n        <\/div>\r\n\r\n        <button onclick=\"calculate()\">Calculate<\/button>\r\n\r\n        <div class=\"result\" id=\"result\">\r\n            <h3>Results:<\/h3>\r\n            <p id=\"discriminant\"><\/p>\r\n            <p id=\"x1\"><\/p>\r\n            <p id=\"x2\"><\/p>\r\n        <\/div>\r\n    <\/div>\r\n\r\n    <script>\r\n        function calculate() {\r\n            \/\/ Reset errors and results\r\n            document.querySelectorAll('.error').forEach(error => error.style.display = 'none');\r\n            document.getElementById('result').classList.remove('show');\r\n\r\n            \/\/ Get input values\r\n            const a = parseFloat(document.getElementById('a').value);\r\n            const b = parseFloat(document.getElementById('b').value);\r\n            const c = parseFloat(document.getElementById('c').value);\r\n\r\n            \/\/ Validate inputs\r\n            if (!a || a === 0) {\r\n                document.getElementById('error-a').style.display = 'block';\r\n                return;\r\n            }\r\n            if (isNaN(b)) {\r\n                document.getElementById('error-b').style.display = 'block';\r\n                return;\r\n            }\r\n            if (isNaN(c)) {\r\n                document.getElementById('error-c').style.display = 'block';\r\n                return;\r\n            }\r\n\r\n            \/\/ Calculate discriminant\r\n            const discriminant = b * b - 4 * a * c;\r\n            let discriminantText, x1Text, x2Text;\r\n\r\n            \/\/ Format the discriminant display\r\n            discriminantText = `Discriminant (\u0394) = ${discriminant.toFixed(4)}`;\r\n\r\n            \/\/ Calculate roots based on discriminant\r\n            if (discriminant > 0) {\r\n                const x1 = (-b + Math.sqrt(discriminant)) \/ (2 * a);\r\n                const x2 = (-b - Math.sqrt(discriminant)) \/ (2 * a);\r\n                x1Text = `x\u2081 = ${x1.toFixed(4)}`;\r\n                x2Text = `x\u2082 = ${x2.toFixed(4)}`;\r\n            } else if (discriminant === 0) {\r\n                const x = -b \/ (2 * a);\r\n                x1Text = x2Text = `x = ${x.toFixed(4)}`;\r\n            } else {\r\n                const realPart = (-b \/ (2 * a)).toFixed(4);\r\n                const imaginaryPart = (Math.sqrt(-discriminant) \/ (2 * a)).toFixed(4);\r\n                x1Text = `x\u2081 = ${realPart} + ${imaginaryPart}i`;\r\n                x2Text = `x\u2082 = ${realPart} - ${imaginaryPart}i`;\r\n            }\r\n\r\n            \/\/ Display results\r\n            document.getElementById('discriminant').textContent = discriminantText;\r\n            document.getElementById('x1').textContent = x1Text;\r\n            document.getElementById('x2').textContent = x2Text;\r\n            document.getElementById('result').classList.add('show');\r\n        }\r\n\r\n        \/\/ Add event listeners for Enter key\r\n        document.querySelectorAll('input').forEach(input => {\r\n            input.addEventListener('keypress', (e) => {\r\n                if (e.key === 'Enter') {\r\n                    calculate();\r\n                }\r\n            });\r\n        });\r\n    <\/script><\/center><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":["post-1739","post","type-post","status-publish","format-standard","hentry","category-calculator"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Quadratic Formula Calculator - DonHit<\/title>\n<meta name=\"description\" content=\"The quadratic formula is a powerful tool for solving quadratic equations, which are equations of the form ax2+bx+c=0.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quadratic Formula Calculator - DonHit\" \/>\n<meta property=\"og:description\" content=\"The quadratic formula is a powerful tool for solving quadratic equations, which are equations of the form ax2+bx+c=0.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/\" \/>\n<meta property=\"og:site_name\" content=\"DonHit - World of Tools\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-27T16:47:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T08:05:17+00:00\" \/>\n<meta name=\"author\" content=\"DonHit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DonHit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Quadratic Formula Calculator - DonHit","description":"The quadratic formula is a powerful tool for solving quadratic equations, which are equations of the form ax2+bx+c=0.","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:\/\/donhit.com\/en\/calculator\/quadratic-formula\/","og_locale":"en_US","og_type":"article","og_title":"Quadratic Formula Calculator - DonHit","og_description":"The quadratic formula is a powerful tool for solving quadratic equations, which are equations of the form ax2+bx+c=0.","og_url":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/","og_site_name":"DonHit - World of Tools","article_published_time":"2024-12-27T16:47:10+00:00","article_modified_time":"2025-02-07T08:05:17+00:00","author":"DonHit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"DonHit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/#article","isPartOf":{"@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/"},"author":{"name":"DonHit","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"headline":"Quadratic Formula Calculator","datePublished":"2024-12-27T16:47:10+00:00","dateModified":"2025-02-07T08:05:17+00:00","mainEntityOfPage":{"@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/"},"wordCount":8,"commentCount":0,"publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"articleSection":["Calculator"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/","url":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/","name":"Quadratic Formula Calculator - DonHit","isPartOf":{"@id":"https:\/\/donhit.com\/en\/#website"},"datePublished":"2024-12-27T16:47:10+00:00","dateModified":"2025-02-07T08:05:17+00:00","description":"The quadratic formula is a powerful tool for solving quadratic equations, which are equations of the form ax2+bx+c=0.","breadcrumb":{"@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/donhit.com\/en\/calculator\/quadratic-formula\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Trang ch\u1ee7","item":"https:\/\/donhit.com\/en\/"},{"@type":"ListItem","position":2,"name":"Calculator","item":"https:\/\/donhit.com\/en\/category\/calculator\/"},{"@type":"ListItem","position":3,"name":"Quadratic Formula Calculator"}]},{"@type":"WebSite","@id":"https:\/\/donhit.com\/en\/#website","url":"https:\/\/donhit.com\/en\/","name":"DonHit - World of tools","description":"","publisher":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/donhit.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148","name":"DonHit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","contentUrl":"https:\/\/donhit.com\/en\/wp-content\/uploads\/2024\/11\/logo-donhit.webp","width":400,"height":267,"caption":"DonHit"},"logo":{"@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/image\/"},"description":"DonHit is a website designed to provide useful tools for everyone. Its primary goal is to support and empower the community. All the tools available on the site are completely free to use.","sameAs":["https:\/\/donhit.com\/en"],"url":"https:\/\/donhit.com\/en\/author\/admin_don\/"}]}},"_links":{"self":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/comments?post=1739"}],"version-history":[{"count":3,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1739\/revisions"}],"predecessor-version":[{"id":2029,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1739\/revisions\/2029"}],"wp:attachment":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/media?parent=1739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/categories?post=1739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/tags?post=1739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}