Jump to content

alzami

Members
  • Posts

    95
  • Joined

  • Last visited

Everything posted by alzami

  1. ok.i did this. var rep1=n.replace(/x^3/g,"math.pow(3,3)"); it shows the replaced form.not evaluating value lyk this 3*math.pow(3,3)
  2. thanks.but will you please explain what is this revserved character is? var rep=n.replace(/x/^2/g,"Math.pow(3,2)"); not working
  3. why the first one works and second one doesn't work? <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#gap{ width:200px; height:50px; border:1px solid black;}</style></head><body><div id="gap"></div><p id="thiss">3*x2+4*x2</p><input type="button" value="replace this" onClick="change();"><script>function change(){ var m=document.getElementById("gap"); var n=document.getElementById("thiss").innerHTML; var rep=n.replace(/x2/g,"Math.pow(3,2)"); m.innerHTML=rep; var t=eval(m.innerHTML); m.innerHTML=t;}</script></body></html> this doesn't work. i used a ( ^ ) sign after x to clearly indicate that it is a square <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>#gap{ width:200px; height:50px; border:1px solid black;}</style></head><body><div id="gap"></div><p id="thiss">3*x^2+4*x^2</p><input type="button" value="replace this" onClick="change();"><script>function change(){ var m=document.getElementById("gap"); var n=document.getElementById("thiss").innerHTML; var rep=n.replace(/x^2/g,"Math.pow(3,2)"); m.innerHTML=rep; var t=eval(m.innerHTML); m.innerHTML=t;}</script></body></html>
  4. can u tell me which misspelled variable are u talking about? i can't find any.? ( codes are ok.i can assure u.problem appeared after i've used the if conditions to manipulate the + and - sign). #yes you can say it is not correct after i put the if statements. #i have coded three formulas,nothing special here. #it gives correct value wihtout if statements . #if statements are only to manipulate sign (+ or -) in the form text field.it has nothing to do with the value of the variable
  5. i am saying the whole code i posted above will give you three roots of a cubic eqn with any coefficient input,But if i used the four if statements it will not work, you can run it in your browser and check it for yourself.
  6. it was working fine before using four if's.only to show + and - sign in the text field i used them.if i don't use them it will show lyk +- 1.87 (if value is negative).to avoid this i used the if's.but instead of helping its creating problem.calculations are ok .i used all kinds of values and result resembles to the vlaues from calculators here i removed the ifs .you can check it yourself.. u need to tap the solve button and select the eqn type it works without if statements. <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>*{margin:0px;padding:0px;}.its{ width:32%; font-size:20px; color:blue; margin:0 auto; }#gets{ width:289px; height:50px; font-size:14px; color:black; background-color:white; }#divs{ width:289px;height:50px;font-size:14px;color:black;background-color:white;display:none;position:absolute;top:13px;left:10px;border:1px solid black;}</style></head><body style="position:relative;"><div id="divs"><a href="#" onClick="solve();"><b>ax^2+bx+c=0</b></a></br><a href="#" onClick="solve_cube();"><b>ax^3+bx^2+cx+d=0</b></a></div><form style="background-color:grey;display:inline-block;height:350px;width:300px;padding:10px;"><input type="text" id="gets" value="calculator(press CLR to begin)"></br><input type="button" value="0" onClick="calc(this.value);" class="its"><input type="button" value="1" onClick="calc(this.value);" class="its" ><input type="button" value="+" onClick="calc(this.value);" class="its"> <input type="button" value="2" onClick="calc(this.value);" class="its"><input type="button" value="3" onClick="calc(this.value);" class="its"><input type="button" value="-" onClick="calc(this.value);" class="its"><input type="button" value="4" onClick="calc(this.value);" class="its"><input type="button" value="5" onClick="calc(this.value);" class="its"><input type="button" value="÷ " onClick="calc(this.value);" class="its" ><input type="button" value="6" onClick="calc(this.value);" class="its"><input type="button" value="7" onClick="calc(this.value);" class="its"><input type="button" value=" ✕" onClick="calc(this.value);" class="its"><input type="button" value="8" onClick="calc(this.value);" class="its"><input type="button" value="9" onClick="calc(this.value);" class="its" ><input type="button" value="=" onClick="ev('gets');" class="its"><input type="button" value="sqrt" onClick="sqr('gets');" class="its" ><input type="button" value="%" onClick="calc(this.value);" class="its"><input type="button" value="CLR" onClick="clr('gets');"class="its" ><input type="button" value="ln" onClick="lnit('gets');" class="its" ><input type="button" value="sin" onClick="trig('gets',Math.sin);" class="its" ><input type="button" value="tan" onClick="trig('gets',Math.tan);" class="its"><input type="button" value="cos" onClick="trig('gets',Math.cos);"class="its" ><input type="button" value="cosec(x)" onClick="rev_trig('gets',Math.sin);" class="its" ><input type="button" value="cot(x)" onClick="rev_trig('gets',Math.tan);" class="its"><input type="button" value="sec(x)" onClick="rev_trig('gets',Math.cos);"class="its" ><input type="button" value="x^(y)" onClick="power('gets');"class="its" ><input type="button" value="log2" onClick="log2('gets');"class="its" ><input type="button" value="log10" onClick="log10('gets');"class="its" ><input type="button" value="solve" onClick="solve_show('divs');"class="its" ><input type="button" value="X" onClick="calc(this.value);"class="its" ></form><script>var i=0;var t=300;function calc(i){document.getElementById("gets").value +=i; }function ev(el){var c=eval(document.getElementById("gets").value); document.getElementById("gets").value=c;}function clr(el){ var m=document.getElementById(el); var c=document.getElementById("divs"); c.style.display="none"; m.value="";}function sqr(el){var c=document.getElementById(el);var v=Math.sqrt(c.value);c.value=v;}function lnit(el){ var c=document.getElementById(el); var v=Math.log(c.value); c.value=v;}function trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var v=oprtr(p); m.value=v;}function power(el){ var m=document.getElementById(el); var v=prompt("put power : "); var p=Math.pow(m.value,v); m.value=p;}function log2(el){ var m=document.getElementById(el); var p=Math.log(m.value)/Math.LN2; m.value=p;}function log10(el){ var m=document.getElementById(el); var p=Math.log(m.value)/Math.LN10; m.value=p;} function rev_trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var d=oprtr(p); var g=1/d; m.value=g;}function solve_show(el){ var m=document.getElementById(el); m.style.display="block";}function solve(){ var m=document.getElementById("divs");m.style.display="none"; var q=document.getElementById("gets"); var a=prompt("put coeff of x^2"); var b=prompt("put coeff of x"); var c=prompt("put value of c"); var p=(b*b-4*a*c); var x1,x2; if(p>0){ var nom=Math.sqrt(p); var de_nom=2*a; x1=(-b+nom)/de_nom; x2=(-b-nom)/de_nom; x1=x1.toFixed(5); x2 =x2.toFixed(5); q.value="x1 ="+ x1 +","+ " x2 ="+ x2 ;} else if(p==0){ x1=x2=(-b)/(2*a); x1=x1.toFixed(5); x2=x2.toFixed(5); q.value="x1 ="+ x1 +","+ " x2 ="+ x2 ; } else{ var real=(-b)/(2*a); real=real.toFixed(2); var imag=Math.sqrt(-p)/(2*a); if(imag<0){ imag=imag.toFixed(2); var neg=-(imag); q.value="x1 ="+ real+"+"+neg+"i"+" , "+ "x2 ="+ real +" "+ imag+ "i" ;} if(imag>0){ imag=imag.toFixed(2); q.value="x1 ="+ real+"-"+imag+"i" +","+ "x2 ="+ real +" +"+ imag+ "i" ;} } }function solve_cube(){ var m=document.getElementById("gets"); var n=document.getElementById("divs"); n.style.display="none"; var a=prompt("put coeff of x^3"); var b=prompt("put coeff of x^2"); var c=prompt("put coeff of x"); var d=prompt("put value of d"); var front=(-b/(3*a)); var root; var for_cube_root1; var for_cube_root2; var cube1; var cube2; var hit; var final1,final2,final3,final4,final5,final6; var three=2*(-Math.pow(-b,3))-(9*a*b*c)+27*(a*a)*d; var last=-Math.pow(-(b*b-3*a*c),3); var under_root=(three*three)-(4*last); if(under_root<0){ root=-Math.sqrt(-under_root); } else if(under_root>0){ root=Math.sqrt(under_root); } for_cube_root1=(1/2)*(three+root); if(for_cube_root1<0){ cube1=-Math.pow(-for_cube_root1,0.33); } else { cube1=Math.pow(for_cube_root1,0.33); } for_cube_root2=(1/2)*(three-root); if(for_cube_root2<0){ cube2=-Math.pow(-for_cube_root2,0.33); } else { cube2=Math.pow(for_cube_root2,0.33); } final1=(1/(3*a))*cube1; final2=(1/(3*a))*cube2; final3=((Math.sqrt(3))/(6*a))*cube1; final4=((-Math.sqrt(3))/(6*a))*cube2; final5=((-Math.sqrt(3))/(6*a))*cube1; final6=((Math.sqrt(3))/(6*a))*cube2; var x1=front-final1-final2; var real=front+(1/(6*a))*(cube1+cube2); var imag1=final3+final4; var imag2=final5+final6; x1=x1.toFixed(2); real=real.toFixed(2); imag1=imag1.toFixed(2); imag2=imag2.toFixed(2); m.value="x1="+x1+",x2="+real+"+"+imag2+"i , x3="+real+"+"+imag1+"i"; }</script></body></html>
  7. i think the problem lies here ... if(imag1<0 && iamg2>0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } after first i (this i in double coute as a string)the following + sign is a seperator ,not a string to show "+" sign. NOT SURE THOUGH!
  8. i have coded newton's interpolatin with c programming.it is way to complex and risky.means there is a great chance to mistake.so i want to stick with it. above code works fine if i use only one statement.To avoid +- imag1value i used those if statements so that if negative value generated "+" will not be there and replaced it with " ". If i dont use 4 if statement together codes works fine.I'hv checked with calculator.All i wanted to know why its not work and how can it be fixed.
  9. i have tried that.lyk...actually only one of them out of four condition can possibly happen.so i think two condition at a time isn't possible here if(imag1<0 && iamg2>0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; }else if(imag1<0 && imag2<0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+""+imag2+"i"; }else if(imag1>0 && imag2>0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } else if(imag1>0 && imag2<0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+""+imag2+"i" ; } never worked.
  10. i need my code to search among four different conditions and only one will be executed.but i have found four if statement in a row doesn't work.how can i fix this.it is for finding roots of a cubic function of the form ax^3+bx^2+cx+d=0. (note i have encountered the same prob before,there were two if statements.so somehow i was able to manage it.but its cofusing to fix four instead of 2.so please help me out) function solve_cube(){ var m=document.getElementById("gets"); var n=document.getElementById("divs"); n.style.display="none"; var a=prompt("put coeff of x^3"); var b=prompt("put coeff of x^2"); var c=prompt("put coeff of x"); var d=prompt("put value of d"); var front=(-b/(3*a)); var root; var for_cube_root1; var for_cube_root2; var cube1; var cube2; var final1,final2,final3,final4,final5,final6; var three=2*(-Math.pow(-b,3))-(9*a*b*c)+27*(a*a)*d; var last=-Math.pow(-(b*b-3*a*c),3); var under_root=(three*three)-(4*last); if(under_root<0){ root=-Math.sqrt(-under_root); } else if(under_root>0){ root=Math.sqrt(under_root); } for_cube_root1=(1/2)*(three+root); if(for_cube_root1<0){ cube1=-Math.pow(-for_cube_root1,0.33); } else { cube1=Math.pow(for_cube_root1,0.33); } for_cube_root2=(1/2)*(three-root); if(for_cube_root2<0){ cube2=-Math.pow(-for_cube_root2,0.33); } else { cube2=Math.pow(for_cube_root2,0.33); } final1=(1/(3*a))*cube1; final2=(1/(3*a))*cube2; final3=((Math.sqrt(3))/(6*a))*cube1; final4=((-Math.sqrt(3))/(6*a))*cube2; final5=((-Math.sqrt(3))/(6*a))*cube1; final6=((Math.sqrt(3))/(6*a))*cube2; var x1=front-final1-final2; var real=front+(1/(6*a))*(cube1+cube2); var imag1=final3+final4; var imag2=final5+final6; x1=x1.toFixed(2); real=real.toFixed(2); imag1=imag1.toFixed(2); imag2=imag2.toFixed(2); if(imag1<0 && iamg2>0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } if(imag1<0 && imag2<0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+""+imag2+"i"; } if(imag1>0 && imag2>0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } if(imag1>0 && imag2<0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+""+imag2+"i" ; } }</script> statements are seperated here if(imag1<0 && iamg2>0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } if(imag1<0 && imag2<0){ m.value="x1="+x1+",x2="+real+""+imag1+"i"+","+"x3="+real+""+imag2+"i"; } if(imag1>0 && imag2>0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+"+"+imag2+"i"; } if(imag1>0 && imag2<0){ m.value="x1="+x1+",x2="+real+"+"+imag1+"i"+","+"x3="+real+""+imag2+"i" ; }
  11. alzami

    Math.pow

    codes of my previous comment works and matches with roots calculated by sci calc.but still feeling confused
  12. alzami

    Math.pow

    i have made it this way and its working.. var cube2=-(Math.pow(-for_cube_root2,0.33)); a negative sign in front of Math.pow and inside bracket befor for_cube_root2.is there any better way to do it.if there please let me know
  13. alzami

    Math.pow

    var for_cube_root2=(1/2)*(three-root); it is -0.39;its ok; i have to calculate -0.30 to the power 0.33.its in the formula.thats what cube2 does.but not working though.
  14. alzami

    Math.pow

    Math.pow(-1,0.33) is also not giving any value.how can it be done?
  15. alzami

    Math.pow

    no.its for finding roots of cubic equation of type ax3+bx2+cx+d=0..though it has three roots.here is only for the first root x1; i am testing with a=1,b=1,c=1,d=1.and cube2 is NAN.i tried with my calculator .if i use(-0.30)^0.33 it give me error.but if i put the - sign out or use no bracket it gives value.but cant figure out what is happening with Math.pow function.cube2 is NAN so x1 auto gets NAN
  16. alzami

    Math.pow

    whay it gives me NAN Math.pow(-.39,0.33); if you want u can check my previous posts where i made a calculator and check "x^y" button actually here var cube2 value is giving NAN; function solve_cube(){ var m=document.getElementById("gets"); var n=document.getElementById("divs"); n.style.display="none"; var a=prompt("put coeff of x^3"); var b=prompt("put coeff of x^2"); var c=prompt("put coeff of x"); var d=prompt("put value of d"); var front=(-b/(3*a)); var three=2*Math.pow(b,3)-(9*a*b*c)+27*(a*a)*d; var last=Math.pow((b*b-3*a*c),3); var under_root=(three*three)-(4*last); var root=Math.sqrt(under_root); var for_cube_root1=(1/2)*(three+root); var for_cube_root2=(1/2)*(three-root); alert(for_cube_root1); var cube1=Math.pow(for_cube_root1,0.33); var cube2=Math.pow(for_cube_root2,0.33); cube1=(1/(3*a))*cube1; cube2=(1/(3*a))*cube2; var x1=front-cube1-cube2; m.value="x1 = "+x1; }
  17. alzami

    complex form

    okay!! i have solved it....thanks for your kind visit
  18. alzami

    complex form

    i have posted my calculator codes in my previous posts.i have made a equation solver .which gives me solution of a quadratic equation if the roots are only real number.if the roots are in complex form or complex root it gives me NAN.how it can be manipulated to show complex roots like (5+3i)?? function solve(){ var m=document.getElementById("divs");m.style.display="none"; var q=document.getElementById("gets"); var a=prompt("put coeff of x^2"); var b=prompt("put coeff of x"); var c=prompt("put value of c"); var p=(b*b-4*a*c); var nom=Math.sqrt(p); var de_nom=2*a; var x1=(-b+nom)/de_nom; var x2=(-b-nom)/de_nom; q.value="x1 ="+ x1 +","+ " x2 ="+ x2 ;} for convinience i am posting the whole code here... <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>.its{ width:32%; font-size:20px; color:blue; margin:0 auto; }#gets{ width:289px; height:50px; font-size:20px; color:black; background-color:white; }#divs{ width:289px;height:50px;font-size:10px;color:black;background-color:white;display:none;position:absolute;top:13px;left:10px;border:1px solid black;}</style></head><body style="position:relative;"><div id="divs"><a href="#" onClick="solve();"><b>ax^2+bx+c=0</b></a></br><a href="#" onClick=><b>ax^3+bx^2+cx+d=0</b></a></div><form style="background-color:grey;display:inline-block;height:350px;width:300px;padding:10px;"><input type="text" id="gets" value="calculator(press CLR to begin)"></br><input type="button" value="0" onClick="calc(this.value);" class="its"><input type="button" value="1" onClick="calc(this.value);" class="its" ><input type="button" value="+" onClick="calc(this.value);" class="its"> <input type="button" value="2" onClick="calc(this.value);" class="its"><input type="button" value="3" onClick="calc(this.value);" class="its"><input type="button" value="-" onClick="calc(this.value);" class="its"><input type="button" value="4" onClick="calc(this.value);" class="its"><input type="button" value="5" onClick="calc(this.value);" class="its"><input type="button" value="÷ " onClick="calc(this.value);" class="its" ><input type="button" value="6" onClick="calc(this.value);" class="its"><input type="button" value="7" onClick="calc(this.value);" class="its"><input type="button" value=" ✕" onClick="calc(this.value);" class="its"><input type="button" value="8" onClick="calc(this.value);" class="its"><input type="button" value="9" onClick="calc(this.value);" class="its" ><input type="button" value="=" onClick="ev('gets');" class="its"><input type="button" value="sqrt" onClick="sqr('gets');" class="its" ><input type="button" value="%" onClick="calc(this.value);" class="its"><input type="button" value="CLR" onClick="clr('gets');"class="its" ><input type="button" value="ln" onClick="lnit('gets');" class="its" ><input type="button" value="sin" onClick="trig('gets',Math.sin);" class="its" ><input type="button" value="tan" onClick="trig('gets',Math.tan);" class="its"><input type="button" value="cos" onClick="trig('gets',Math.cos);"class="its" ><input type="button" value="cosec(x)" onClick="rev_trig('gets',Math.sin);" class="its" ><input type="button" value="cot(x)" onClick="rev_trig('gets',Math.tan);" class="its"><input type="button" value="sec(x)" onClick="rev_trig('gets',Math.cos);"class="its" ><input type="button" value="x^(y)" onClick="power('gets');"class="its" ><input type="button" value="log2" onClick="log2('gets');"class="its" ><input type="button" value="log10" onClick="log10('gets');"class="its" ><input type="button" value="solve" onClick="solve_show('divs');"class="its" ><input type="button" value="X" onClick="calc(this.value);"class="its" ></form><script>var i=0;var t=300;function calc(i){document.getElementById("gets").value +=i; }function ev(el){var c=eval(document.getElementById("gets").value); document.getElementById("gets").value=c;}function clr(el){ var m=document.getElementById(el); var c=document.getElementById("divs"); c.style.display="none"; m.value="";}function sqr(el){var c=document.getElementById(el);var v=Math.sqrt(c.value);c.value=v;}function lnit(el){ var c=document.getElementById(el); var v=Math.log(c.value); c.value=v;}function trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var v=oprtr(p); m.value=v;}function power(el){ var m=document.getElementById(el); var v=prompt("put power : "); var p=Math.pow(m.value,v); m.value=p;}function log2(el){ var m=document.getElementById(el); var p=Math.log(m.value)/Math.LN2; m.value=p;}function log10(el){ var m=document.getElementById(el); var p=Math.log(m.value)/Math.LN10; m.value=p;} function rev_trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var d=oprtr(p); var g=1/d; m.value=g;}function solve_show(el){ var m=document.getElementById(el); m.style.display="block";}function solve(){ var m=document.getElementById("divs");m.style.display="none"; var q=document.getElementById("gets"); var a=prompt("put coeff of x^2"); var b=prompt("put coeff of x"); var c=prompt("put value of c"); var p=(b*b-4*a*c); var nom=Math.sqrt(p); var de_nom=2*a; var x1=(-b+nom)/de_nom; var x2=(-b-nom)/de_nom; q.value="x1 ="+ x1 +","+ " x2 ="+ x2 ;}</script></body></html>
  19. Math.log(n)/Math.LN10; is it a complete statement.or it meant i can use Math.log or Math.LN10?i have never encountered such kind of statement. if u see my calculator codes i already used Math.log. it says Math.log is an e based logarithm which is different frm 10 based logarithm
  20. the problem is if i want log of 100 it gives 2.its not the problem.problem is if i want log of 104 ,it gives me no value.but normal scientific calculator gives value of log(104) .how can i persuade javascript to to such calculation?
  21. alzami

    NaN

    thanks a lot .
  22. alzami

    NaN

    but its not showing anything inside the form text field.
  23. alzami

    NaN

    thanks.but i am cofused about the final portion of my problem. and it is ,is this right or not?i mean can i write inside a FORM lyk this c.value="x1 :"+ x1 + " x2 :"+ x2 ;
  24. alzami

    NaN

    <!doctype html><html><head><meta charset="utf-8"><title>Untitled Document</title><style>.its{ width:32%; font-size:20px; color:blue; margin:0 auto; }#gets{ width:289px; height:50px; font-size:20px; color:black; background-color:white; }#divs{ width:289px;height:50px;font-size:20px;color:red;background-color:gray;display:none;position:absolute;top:13px;left:10px;border:1px solid black;}</style></head><body style="position:relative;"><div id="divs"><a href="#" onClick="solve();">ax^2+bx+c=0</a></div><form style="background-color:grey;display:inline-block;height:350px;width:300px;padding:10px;"><input type="text" id="gets" value="calculator(press CLR to begin)"></br><input type="button" value="0" onClick="calc(this.value);" class="its"><input type="button" value="1" onClick="calc(this.value);" class="its" ><input type="button" value="+" onClick="calc(this.value);" class="its"> <input type="button" value="2" onClick="calc(this.value);" class="its"><input type="button" value="3" onClick="calc(this.value);" class="its"><input type="button" value="-" onClick="calc(this.value);" class="its"><input type="button" value="4" onClick="calc(this.value);" class="its"><input type="button" value="5" onClick="calc(this.value);" class="its"><input type="button" value="/" onClick="calc(this.value);" class="its" ><input type="button" value="6" onClick="calc(this.value);" class="its"><input type="button" value="7" onClick="calc(this.value);" class="its"><input type="button" value="*" onClick="calc(this.value);" class="its"><input type="button" value="8" onClick="calc(this.value);" class="its"><input type="button" value="9" onClick="calc(this.value);" class="its" ><input type="button" value="=" onClick="ev('gets');" class="its"><input type="button" value="sqrt" onClick="sqr('gets');" class="its" ><input type="button" value="%" onClick="calc(this.value);" class="its"><input type="button" value="CLR" onClick="clr('gets');"class="its" ><input type="button" value="ln" onClick="lnit('gets');" class="its" ><input type="button" value="sin" onClick="trig('gets',Math.sin);" class="its" ><input type="button" value="tan" onClick="trig('gets',Math.tan);" class="its"><input type="button" value="cos" onClick="trig('gets',Math.cos);"class="its" ><input type="button" value="cosec(x)" onClick="rev_trig('gets',Math.sin);" class="its" ><input type="button" value="cot(x)" onClick="rev_trig('gets',Math.tan);" class="its"><input type="button" value="sec(x)" onClick="rev_trig('gets',Math.cos);"class="its" ><input type="button" value="x^(y)" onClick="power('gets');"class="its" ><input type="button" value="log2" onClick="log2('gets');"class="its" ><input type="button" value="log10" onClick="log10('gets');"class="its" ><input type="button" value="solve" onClick="solve_show('divs');"class="its" ><input type="button" value="X" onClick="calc(this.value);"class="its" ></form><script>var i=0;var t=300;function calc(i){document.getElementById("gets").value +=i; }function ev(el){var c=eval(document.getElementById("gets").value); document.getElementById("gets").value=c;}function clr(el){ var m=document.getElementById(el); m.value="";}function sqr(el){var c=document.getElementById(el);var v=Math.sqrt(c.value);c.value=v;}function lnit(el){ var c=document.getElementById(el); var v=Math.log(c.value); c.value=v;}function trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var v=oprtr(p); m.value=v;}function power(el){ var m=document.getElementById(el); var v=prompt("put power : "); var p=Math.pow(m.value,v); m.value=p;}function log2(el){ var m=document.getElementById(el); for(;{ var d=Math.pow(2,i); if(d==m.value){ m.value=i; i=0; break; } i++; }}function log10(el){ var m=document.getElementById(el); for(;{ var d=Math.pow(10,i); if(d==m.value){ m.value=i; i=0; break; } i++; }} function rev_trig(el,oprtr){ var m=document.getElementById(el); var p=(m.value)*( Math.PI/180); var d=oprtr(p); var g=1/d; m.value=g;}function solve_show(el){ var m=document.getElementById(el); m.style.display="block";}function solve(){ var m=document.getElementById("divs"); m.style.display="none"; var c=document.getElementById("gets"); var a=prompt("put coeff of x^2"); var b=prompt("put coeff of x"); var c=prompt("put value of c"); var p=(b*b-4*a*c); var nom=Math.sqrt(p); var de_nom=2*a; var x1=(-b+nom)/de_nom; var x2=(-b-nom)/de_nom; c.value="x1 :"+ x1 + " x2 :"+ x2 ;}</script></body></html> problem is.... this script always giving x1 and x2 value NaN.what might be the reason? function solve(){ var m=document.getElementById("divs"); m.style.display="none"; var c=document.getElementById("gets"); var a=prompt("put coeff of x^2"); var b=prompt("put coeff of x"); var c=prompt("put value of c"); var p=(b*b-4*a*c); var nom=Math.sqrt(p); var de_nom=2*a; var x1=(-b+nom)/de_nom; var x2=(-b-nom)/de_nom; c.value="x1 :"+ x1 + "x2 :"+ x2 ;} is it ok? c.value="x1 :"+ x1 + " x2 :"+ x2 ;
×
×
  • Create New...