Hi all. I'm going back to college. I have decided to create a calculator for this purpose and this purpose alone.
I'm having a few problems..
No matter WHAT u click, as long as theres a # in there, the signs "*, /, +, or -" do NOT add more than ONE "*, /, +, or -", as long as theres a # before and / or after the sign. what i mean is u can do 3+3+3, but u cant do +3+3+3 or 3+++3 or +3+3+3+ or +++3..
this code ALMOST works. except its backwards.
instead of deleting any operators before the # and any double operators or 2 different operators both before or after #, it deletes the 1st 2 characters.. :S
I'm having a bit of a problem w/ code.
I also need to detect if u hit more than 1 sign, and make it stop it.Code:<html> <head> <script type="text/javascript"> function trim1(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); } function twoConsecutiveChars(str) { if(document.forms.CALCULATOR.ans.value != ""){ for (var i = 0; i < str.length; i++) { if (str.charAt(i) == str.charAt(i+1)) { alert('no'); document.forms.CALCULATOR.ans.value = trim1(str.charAt(-3)); } } } } function calc( btn ) { var num = parseInt(btn.value,13); if (isNaN(num) ) { if(document.forms.CALCULATOR.ans.value != twoConsecutiveChars(document.forms.CALCULATOR.ans.value)){ document.forms.CALCULATOR.ans.value += btn.value; } else if(btn.value == "=" && twoConsecutiveChars(document.forms.CALCULATOR.ans.value)){ document.forms.CALCULATOR.ans.value = eval(document.forms.CALCULATOR.ans.value); } } else { document.forms.CALCULATOR.ans.value += num; } } </script> <style type="text/css"> form#CALCULATOR input { width: 30px; } form#CALCULATOR .ans1 { width: 92px; } </style> </head> <body> <form id="CALCULATOR"> <input type="text" class="ans1" name="ans" size="20"><br> <script> for(var x=0;x<=12;x++){ if(x<=9){ document.write('<input type="button" class="btns" value="'+x+'" onclick="calc(this);">'); }else if(x==10){ var x1="*"; }else if(x==11){ var x1="/"; }else if(x==12){ var x1="="; } if(x>9){ document.write('<input type="button" class="btns" value="'+x1+'" onclick="calc(this);">'); } if(x==2 || x==5 || x==8 || x==11){ document.write('<br>'); } } </script> </form> </body> </html>
like this:
1/*2 or */1+2 or 2*/ or */1+2*/ or */1+-2*/



Reply With Quote

Bookmarks