{"id":1735,"date":"2024-12-27T09:15:35","date_gmt":"2024-12-27T09:15:35","guid":{"rendered":"https:\/\/donhit.com\/en\/?p=1735"},"modified":"2025-02-07T08:03:47","modified_gmt":"2025-02-07T08:03:47","slug":"scientific","status":"publish","type":"post","link":"https:\/\/donhit.com\/en\/calculator\/scientific\/","title":{"rendered":"Scientific Calculator"},"content":{"rendered":"<p><center>\r\n    <div class=\"calculator\">\r\n        <div class=\"display\">\r\n            <div class=\"previous-operand\"><\/div>\r\n            <div class=\"current-operand\">0<\/div>\r\n        <\/div>\r\n        <div class=\"buttons\">\r\n            <button class=\"function\">sin<\/button>\r\n            <button class=\"function\">cos<\/button>\r\n            <button class=\"function\">tan<\/button>\r\n            <button class=\"function\">ln<\/button>\r\n            <button class=\"function\">log<\/button>\r\n            \r\n            <button class=\"function\">\u221a<\/button>\r\n            <button class=\"function\">x\u00b2<\/button>\r\n            <button class=\"function\">x\u02b8<\/button>\r\n            <button class=\"function\">(<\/button>\r\n            <button class=\"function\">)<\/button>\r\n            \r\n            <button>7<\/button>\r\n            <button>8<\/button>\r\n            <button>9<\/button>\r\n            <button class=\"operator\">\u00f7<\/button>\r\n            <button class=\"function\">DEL<\/button>\r\n            \r\n            <button>4<\/button>\r\n            <button>5<\/button>\r\n            <button>6<\/button>\r\n            <button class=\"operator\">\u00d7<\/button>\r\n            <button class=\"function\">AC<\/button>\r\n            \r\n            <button>1<\/button>\r\n            <button>2<\/button>\r\n            <button>3<\/button>\r\n            <button class=\"operator\">-<\/button>\r\n            <button class=\"function\">%<\/button>\r\n            \r\n            <button>0<\/button>\r\n            <button>.<\/button>\r\n            <button class=\"operator\">\u03c0<\/button>\r\n            <button class=\"operator\">+<\/button>\r\n            <button class=\"equals\">=<\/button>\r\n        <\/div>\r\n    <\/div>\r\n\r\n    <script>\r\n        class Calculator {\r\n            constructor() {\r\n                this.previousOperand = '';\r\n                this.currentOperand = '0';\r\n                this.operation = undefined;\r\n                this.updateDisplay();\r\n            }\r\n\r\n            clear() {\r\n                this.previousOperand = '';\r\n                this.currentOperand = '0';\r\n                this.operation = undefined;\r\n            }\r\n\r\n            delete() {\r\n                this.currentOperand = this.currentOperand.toString().slice(0, -1);\r\n                if (this.currentOperand === '') this.currentOperand = '0';\r\n            }\r\n\r\n            appendNumber(number) {\r\n                if (number === '.' && this.currentOperand.includes('.')) return;\r\n                if (this.currentOperand === '0' && number !== '.') {\r\n                    this.currentOperand = number.toString();\r\n                } else {\r\n                    this.currentOperand = this.currentOperand.toString() + number.toString();\r\n                }\r\n            }\r\n\r\n            chooseOperation(operation) {\r\n                if (this.currentOperand === '') return;\r\n                if (this.previousOperand !== '') {\r\n                    this.compute();\r\n                }\r\n                this.operation = operation;\r\n                this.previousOperand = this.currentOperand;\r\n                this.currentOperand = '';\r\n            }\r\n\r\n            compute() {\r\n                let computation;\r\n                const prev = parseFloat(this.previousOperand);\r\n                const current = parseFloat(this.currentOperand);\r\n                if (isNaN(prev) || isNaN(current)) return;\r\n\r\n                switch (this.operation) {\r\n                    case '+':\r\n                        computation = prev + current;\r\n                        break;\r\n                    case '-':\r\n                        computation = prev - current;\r\n                        break;\r\n                    case '\u00d7':\r\n                        computation = prev * current;\r\n                        break;\r\n                    case '\u00f7':\r\n                        computation = prev \/ current;\r\n                        break;\r\n                    case 'x\u02b8':\r\n                        computation = Math.pow(prev, current);\r\n                        break;\r\n                    default:\r\n                        return;\r\n                }\r\n\r\n                this.currentOperand = computation;\r\n                this.operation = undefined;\r\n                this.previousOperand = '';\r\n            }\r\n\r\n            specialFunction(func) {\r\n                let result;\r\n                const current = parseFloat(this.currentOperand);\r\n\r\n                switch(func) {\r\n                    case 'sin':\r\n                        result = Math.sin(current * Math.PI \/ 180);\r\n                        break;\r\n                    case 'cos':\r\n                        result = Math.cos(current * Math.PI \/ 180);\r\n                        break;\r\n                    case 'tan':\r\n                        result = Math.tan(current * Math.PI \/ 180);\r\n                        break;\r\n                    case 'ln':\r\n                        result = Math.log(current);\r\n                        break;\r\n                    case 'log':\r\n                        result = Math.log10(current);\r\n                        break;\r\n                    case '\u221a':\r\n                        result = Math.sqrt(current);\r\n                        break;\r\n                    case 'x\u00b2':\r\n                        result = Math.pow(current, 2);\r\n                        break;\r\n                    case '%':\r\n                        result = current \/ 100;\r\n                        break;\r\n                    case '\u03c0':\r\n                        result = Math.PI;\r\n                        break;\r\n                }\r\n\r\n                this.currentOperand = result;\r\n            }\r\n\r\n            updateDisplay() {\r\n                document.querySelector('.current-operand').textContent = this.currentOperand;\r\n                if (this.operation != null) {\r\n                    document.querySelector('.previous-operand').textContent = \r\n                        `${this.previousOperand} ${this.operation}`;\r\n                } else {\r\n                    document.querySelector('.previous-operand').textContent = '';\r\n                }\r\n            }\r\n        }\r\n\r\n        const calculator = new Calculator();\r\n\r\n        document.querySelectorAll('button').forEach(button => {\r\n            button.addEventListener('click', () => {\r\n                if (button.classList.contains('function')) {\r\n                    if (button.textContent === 'AC') {\r\n                        calculator.clear();\r\n                    } else if (button.textContent === 'DEL') {\r\n                        calculator.delete();\r\n                    } else {\r\n                        calculator.specialFunction(button.textContent);\r\n                    }\r\n                } else if (button.classList.contains('operator')) {\r\n                    calculator.chooseOperation(button.textContent);\r\n                } else if (button.classList.contains('equals')) {\r\n                    calculator.compute();\r\n                } else {\r\n                    calculator.appendNumber(button.textContent);\r\n                }\r\n                calculator.updateDisplay();\r\n            });\r\n        });\r\n\r\n        \/\/ Keyboard support\r\n        document.addEventListener('keydown', e => {\r\n            if (e.key >= '0' && e.key <= '9' || e.key === '.') {\r\n                calculator.appendNumber(e.key);\r\n            }\r\n            if (e.key === '+' || e.key === '-' || e.key === '*' || e.key === '\/') {\r\n                let operation = e.key;\r\n                if (operation === '*') operation = '\u00d7';\r\n                if (operation === '\/') operation = '\u00f7';\r\n                calculator.chooseOperation(operation);\r\n            }\r\n            if (e.key === 'Enter' || e.key === '=') {\r\n                calculator.compute();\r\n            }\r\n            if (e.key === 'Backspace') {\r\n                calculator.delete();\r\n            }\r\n            if (e.key === 'Escape') {\r\n                calculator.clear();\r\n            }\r\n            calculator.updateDisplay();\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-1735","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>Scientific Calculator - DonHit<\/title>\n<meta name=\"description\" content=\"Scientific calculators are equipped with advanced functionalities that cater to diverse mathematical and engineering needs.\" \/>\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\/scientific\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scientific Calculator - DonHit\" \/>\n<meta property=\"og:description\" content=\"Scientific calculators are equipped with advanced functionalities that cater to diverse mathematical and engineering needs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/donhit.com\/en\/calculator\/scientific\/\" \/>\n<meta property=\"og:site_name\" content=\"DonHit - World of Tools\" \/>\n<meta property=\"article:published_time\" content=\"2024-12-27T09:15:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T08:03:47+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":"Scientific Calculator - DonHit","description":"Scientific calculators are equipped with advanced functionalities that cater to diverse mathematical and engineering needs.","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\/scientific\/","og_locale":"en_US","og_type":"article","og_title":"Scientific Calculator - DonHit","og_description":"Scientific calculators are equipped with advanced functionalities that cater to diverse mathematical and engineering needs.","og_url":"https:\/\/donhit.com\/en\/calculator\/scientific\/","og_site_name":"DonHit - World of Tools","article_published_time":"2024-12-27T09:15:35+00:00","article_modified_time":"2025-02-07T08:03:47+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\/scientific\/#article","isPartOf":{"@id":"https:\/\/donhit.com\/en\/calculator\/scientific\/"},"author":{"name":"DonHit","@id":"https:\/\/donhit.com\/en\/#\/schema\/person\/0c6ff7dcd8ba4810c56a532f09c33148"},"headline":"Scientific Calculator","datePublished":"2024-12-27T09:15:35+00:00","dateModified":"2025-02-07T08:03:47+00:00","mainEntityOfPage":{"@id":"https:\/\/donhit.com\/en\/calculator\/scientific\/"},"wordCount":9,"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\/scientific\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/donhit.com\/en\/calculator\/scientific\/","url":"https:\/\/donhit.com\/en\/calculator\/scientific\/","name":"Scientific Calculator - DonHit","isPartOf":{"@id":"https:\/\/donhit.com\/en\/#website"},"datePublished":"2024-12-27T09:15:35+00:00","dateModified":"2025-02-07T08:03:47+00:00","description":"Scientific calculators are equipped with advanced functionalities that cater to diverse mathematical and engineering needs.","breadcrumb":{"@id":"https:\/\/donhit.com\/en\/calculator\/scientific\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/donhit.com\/en\/calculator\/scientific\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/donhit.com\/en\/calculator\/scientific\/#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":"Scientific 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\/1735","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=1735"}],"version-history":[{"count":4,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1735\/revisions"}],"predecessor-version":[{"id":2032,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/posts\/1735\/revisions\/2032"}],"wp:attachment":[{"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/media?parent=1735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/categories?post=1735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/donhit.com\/en\/wp-json\/wp\/v2\/tags?post=1735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}