I am writing a program with js to solve some maths problems.
I think it’s better to show it first:
JS FILE:
const btn = document.querySelector(".sab");
const javab = document.getElementById("javabi");
var index = 0;
var lan = 0;
var numlist = ["|x|", "√", "⊆", "∈", "sin", "cos", "tan", "cot", "!", "*", "-", "/", "+","cone", "pyramid"]
var numbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-"]
var numbbers = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "-9", "-", "+", "/", "*", "**"]
var signs = ["+", "-", "/", "*"];
// document.getElementById("bist").value
document.querySelectorAll('textarea').forEach(el => {
el.style.height = el.setAttribute('style', 'height: ' + el.scrollHeight + 'px');
el.classList.add('auto');
el.addEventListener('input', e => {
el.style.height = 'auto';
el.style.height = (el.scrollHeight) + 'px';
});
});
function tunelli(phrase) {
}
function proccess() {
var base = document.getElementById("bist").value;
if (base.includes("solve:")) {
let lst = base.split(":");
javab.innerHTML = Manager(lst, base);
} else {
let lst = base.split(" ");
javab.innerHTML = Manager(lst, base);
}
}
function isnum(parameter) {
let result = false;
for (const letter of parameter) {
if (numbers.includes(letter)) {
result = true;
} else {
result = false;
break;
}
}
return result;
}
function dependensise(lstf, lsts) {
let boolp = false;
for (let index = 0; index < lstf.length; index++) {
const element = lstf[index];
if (lsts.includes(element)) {
boolp = true;
}
else if (isnum(element)) {
boolp = true;
}
else {
boolp = false;
break;
}
}
return boolp;
}
function DTS(par) {
let rt = par;
rt = rt.replace(/s/g, "");
return rt;
}
function thevariables(input) {
let pas = "";
for (const letter of input) {
if (!numbbers.includes(letter) && !signs.includes(letter)) {
pas = letter;
break;
}
}
return pas;
}
function Manager(listnumbers, base) {
if (base.includes("solve:")) {
if (listnumbers[1].includes(",")) {
let javaby = [];
let mine = DTS(listnumbers[1]);
javaby = multipleequations(mine.split(","));
return javaby;
} else {
let javaby = 0;
let mine = DTS(listnumbers[1]);
javaby = solveoneequation(mine, thevariables(mine));
return javaby;
}
} else {
var stri = "";
for (const obj of listnumbers) {
if (numlist.includes(obj.split(":")[0])) {
var basic= obj.split(":")
if (basic[0] == "|x|") {
stri += abs(basic[1]);
}else if (basic[0] == "cot") {
stri += cot(basic[1]);
}else if (basic[0] == "sin") {
stri += sin(basic[1]);
}else if (basic[0] == "cos") {
stri += cos(basic[1]);
}else if (basic[0] == "tan") {
stri += tan(basic[1]);
}else if (basic[0] == "⊆") {
stri += mem(basic[1]);
}else if (basic[0] == "∈") {
stri += subdivision(basic[1]);
}else if (basic[0] == "√") {
stri += sqrt(basic[1]);
}else if (basic[0] == "cone") {
stri += Cone(basic[1].split(",")[0],basic[1].split(",")[1]);
}else if (basic[0] == "pyramid") {
stri += Pyramid(basic[1].split(",")[0],basic[1].split(",")[1]);
}else if (basic[0] == "*") {
stri += "*";
}else if (basic[0] == "+") {
stri += "+";
}else if (basic[0] == "-") {
stri += "-";
}else if (basic[0] == "/") {
stri += "/";
}else if (basic[0] == "!") {
stri += factorial(basic[1]);
}else{
stri = "نامعتبر"
}
}else{
stri += obj;
}
}
try{
stri = eval(stri);
}catch{
stri = "نامعتبر";
}
return stri
}
}
function abs(num) {
var number = Math.abs(num);
return number;
}
function sqrt(num) {
return Math.sqrt(num);
}
function subdivision(num) {
return 2 ** num;
}
function Cone(r, h) {
return (1 / 3) * Math.PI * r ** 2 * h;
}
function Pyramid(s, h) {
return (s * h) / 2;
}
function mem(number) {
return Math.log2(number);
}
function sin(number) {
return Math.sin(number);
}
function cos(number) {
return Math.cos(number);
}
function tan(number) {
return Math.tan(number);
}
function cot(number) {
return 1 / Math.tan(number);
}
function solveoneequation(equation, variable) {
return nerdamer.solve(equation, variable);
}
function multipleequations(list) {
return nerdamer.solveEquations(list);
}
function factorial(n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
btn.addEventListener("click", proccess);
function butclick(input) {
if (document.querySelector("#bist").value == "type...") {
document.querySelector("#bist").value == "";
}
if (input == "delete") {
document.querySelector("#bist").value = "";
}
else {
document.querySelector("#bist").value += `${input}`;
}
document.querySelector("#bist").focus();
}
function iswriting() {
javab.innerHTML = "در حال نوشتن";
}
document.getElementById("bist").addEventListener("focus", iswriting);
and about
HTML FILE:
<div class="main">
<textarea rows="1" id="bist">type...</textarea>
<button class="sab"><i class="fa fa-play"></i></button>
</div>
<div class="left-c">
<button onclick="butclick('√:')" class="but-g">√</button>
<button onclick="butclick('∈:')" class="but-g">n(⊆)</button>
<button onclick="butclick('⊆:')" class="but-g">n(∈)</button>
<button onclick="butclick('cone:')" class="but-g" >مخروط</button>
<button onclick="butclick('pyramid:')" class="but-g">هرم</button>
<button onclick="butclick('solve:')" class="but-g">
معادله
</button>
<button class="but-g">
<a href="https://phet.colorado.edu/sims/html/center-and-variability/latest/center-and-variability_en.html">آزمایشگاه میانگین</a>
</button>
<button class="but-g">
<a href="https://phet.colorado.edu/sims/html/number-compare/latest/number-compare_en.html">آزمایشگاه مقایسه اعداد</a>
</button>
<button class="but-g">
<a href="https://phet.colorado.edu/sims/html/number-line-integers/latest/number-line-integers_en.html">آسانسور اعداد</a>
</button>
<button class="but-g">
<a href="https://phet.colorado.edu/sims/html/fractions-mixed-numbers/latest/fractions-mixed-numbers_en.html">جمع های کسری</a>
</button>
<button onclick="butclick('|x|:')" class="but-g">قدر مطلق</button>
<button onclick="butclick('delete')" class="but-g">
پاک کن
</button>
</div>
<div class="answer">
<p id="javabi">ok</p>
</div>
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"
></script>
<script type="text/javascript">
$.ajax({
type: "POST",
url: "{% url 'komaki:Pishrafteh' %}",
data: {
text: "Mean",
csrfmiddlewaretoken: "{{ csrf_token }}",
}
});
</script>
<script src="{% static 'pish.js' %}"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/nerdamer.core.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Algebra.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Calculus.js"></script>
<script src="https://cdn.jsdelivr.net/npm/nerdamer@latest/Solve.js"></script>
and
CSS FILE:
.selected{
background-color: rgb(102, 201, 140);
}
textarea {
resize: none;
}
textarea.auto {
overflow-y: hidden;
}
textarea {
-webkit-appearance: none;
box-sizing: border-box;
outline: none;
width: 100%;
max-width: 240px;
font-size: 14px;
font-family: "Vazir";
line-height: 22px;
padding: 16px 20px;
border-radius: 15px;
color: #404660;
border: none;
background: #fff;
transition: box-shadow 0.25s;
box-shadow: inset 0 0 0 1px var(--border-color, #E1E6F9), 0 0 0 3px var(--focus-color, transparent);
}
textarea:focus {
--focus-color: #ECEFFC;
}
textarea:focus,
textarea:hover {
--border-color: #BBC1E1;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
background: #F6F8FF;
}
pre {
margin: 60px 0 0 0;
padding: 20px 24px;
border-radius: 15px;
background: #171827;
}
pre code {
font-family: "Fira Mono";
color: #BBC1E1;
line-height: 1.4;
font-size: 12px;
}
pre code .token.function {
color: #5C86FF;
}
pre code .token.string {
color: #F0B849;
}
pre code .token.parameter {
color: #CB7DD0;
}
pre code .token.punctuation {
color: #8A91B4;
}
button {
position: relative;
display: inline-block;
margin: 15px;
padding: 15px 30px;
text-align: center;
font-size: 18px;
letter-spacing: 1px;
text-decoration: none;
color: #725AC1;
background: transparent;
cursor: pointer;
transition: ease-out 0.5s;
border: 2px solid #725AC1;
border-radius: 10px;
box-shadow: inset 0 0 0 0 #725AC1;
}
button:hover {
color: white;
box-shadow: inset 0 -100px 0 0 #725AC1;
}
button:active {
transform: scale(0.9);
}
.main {
display: flex;
}
.notifications-container {
width: 320px;
height: auto;
font-size: 0.875rem;
line-height: 1.25rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
.flex {
display: flex;
}
.flex-shrink-0 {
flex-shrink: 0;
}
.success {
padding: 1rem;
border-radius: 0.375rem;
background-color: rgb(240 253 244);
}
.success-prompt-wrap {
margin-left: 0.75rem;
}
.success-prompt-heading {
font-weight: bold;
color: rgb(22 101 52);
}
.success-prompt-prompt {
margin-top: 0.5rem;
color: rgb(21 128 61);
}
now if we write cone:4,6 it can solve it. but is we write the cone:(cone:6,7),8 or some more harder like pyramid:(cone:(cone:8,9),9),(cone:5,6) it can’t handle it. How can I find a way to handle this? I know that I can solve it from the innermost to the outermost, but how can I find them in a loop?
I think I said all of important things.
nothing here.