Javascript java脚本中出现意外的令牌错误,希望查看它是否工作正常? java脚本中出现意外的令牌错误,希望查看它是否工作正常 我的脚本出错了,我是新手,所以我无法识别它是什么,这个脚本是否工作正常 这个脚本是用于计算器的,所以请检查它是否正确。
JAva脚本Javascript java脚本中出现意外的令牌错误,希望查看它是否工作正常? java脚本中出现意外的令牌错误,希望查看它是否工作正常 我的脚本出错了,我是新手,所以我无法识别它是什么,这个脚本是否工作正常 这个脚本是用于计算器的,所以请检查它是否正确。,javascript,php,compiler-errors,Javascript,Php,Compiler Errors,JAva脚本 var decimalPoint = enter = entered = operatorSign = rootNpower_Sign = flo = math = M = firstI = first = second=second1 = answer = theanswer = result = peSign =""; var opsCheck = dotCounter = 0; var removeFirstZero=""
var decimalPoint = enter = entered = operatorSign = rootNpower_Sign = flo = math = M = firstI = first = second=second1 = answer = theanswer = result = peSign ="";
var opsCheck = dotCounter = 0;
var removeFirstZero="";
function dot(b){
if(decimalPoint ==""){
enter = entered=b;
first+=enter;
entered+=enter;
decimalPoint = ".";
dotCounter = 0;
return first;
}else{
return first;
}
}
//Control what happened when Pi and euler is click
function PE(b){
decimalPoint=".";
dotCounter =15;
var cons =b;
if (peSign == ""){
if(operatorSign !="" && first=="" + operatorSign){
first =(cons=""PI)? Math.PI:Math.E;
}
else if(operatorSign != "" && first >0 || first <0){
first =(cons == "PI")?first + "*" +Math.E;
}
else if(first!="" && operatorSign!=""){
first+=(cons = "PI")? Math.PI:Math.E;
}
else if(operatorSign =="" && first !=""){
first=(cons=="PI")? first+"*" +Math.PI:first+"*"+Math.E;
}
else{
first=(cons=="PI")?Math.PI:Math.E;
}
return first;
}
function mp(){
M =first;
first=M;
return first;
}
function mr(){
first = M;
return first;
}
function c(c){
document.getElementById("display1").innerHTML = decimalPoint=operatorSign=rootNpower_Sign=entered=math first=firstI=second=second1=answer=theanswer=flo=M="";
return "";
}
function mathematics()
{
if(math=="sqr"){
result=firstI*firstI;
}else if(math=="cube"){
result=firstI*firstI*firstI;
}
else if(math=="sqrt"){
result=Math.sqrt(firstI);
}
else if(math=="cubert"){
result=Math.cubert(firstI);
}
else if(math =="negpos"){
result=firstI*-1;
}
else if(math=="sine"){
result=Math.sin(firstI);
}
else if(math=="cosine"){
result=Math.cos(firstI);
}
else if(math=="tangent")
{
result=Math.tan(firstI);
}
else if(math =="ln"){
result=Math.log(firstI);
}
else if(math=="logTen"){
result=Math.log10(firstI);
}
else if(math=="rand"){
result=Math.round(firstI);
}
else if(math=="res")
{
result=1/firstI;
}
else if(math=="fact"){
n=firstI;
firstI=1;
while(n>1){
firstI*=n;
n-+1;
}
result=firstI;
}decimalPoint=(Math.round(result)==result)? "": ".";
}
function prep(){
second=eval(second);
first=eval(first);
}
function maths(a){
math=a;
try{
if(operatorSign=="+"){
prep();
firstI=first-second;
mathematics();
first=second+"+"+result;
}
else if(operatorSign=="-"){
prep();
firstI=second-first;
mathematics();
first=second+"-"+"("+result")";
}
else if(operatorSign=="*"){
prep();
firstI=second/first;
mathematics();
first=second+"/"+result;
}
else{
firstI=first;
mathematics();
first=result;
}
return first;
}
}
function digit(b){
opsCheck=0;
dotCounter++;
if(first==Infinity || first ==NaN){
first=0;
}
peSign="pes";
entered=b;
if(rootNpower_Sign !=""){
first=(first==="0" && entered:first+entered);
return second1 +firstI*rootNpower_Sign*first;
}
else{
first=(first==="0" && entered:first+entered);
theanswer=eval(first)+"";
if(theanswer.length>14){
theanswer=Math.abs((theanswer*1).toPrecision(14));
}
document.getElementById("display1").innerHTML=first;
return theanswer;
}
}
var thebase ="";
function base(a){
thebase=a;
first*=1;
if(thebase =="bin"){
firstII=first.topString(2);
}else if(thebase=="oct"){
firstII=first.topString(8);
}
else if(thebase=="hex"){
firstII=first.topString(16);
}
return firstII;
}
function themes(thm){
theme=thm;
el=document.getElementsByClass("div");
if(theme==1){
el[0].id ="theme1";
}
else if(theme==2){
el[0].id="theme2";
}
else if(theme==3){
el[0].id="theme3";
}
else {
el[0].id="theme4";
}
}
//backspace
function bsp()
{
first +="";
dotCounter--;
decimalPoint=dotCounter>=0 ? "." :"";
first=first.substr(0,first.length-1);
document.getElementById("display1").innerHTML =-first;
try{
eval(first);
return first;
}
catch (first){
eval(first);
return "";
}
}
funvction pow(){
first*=1;
result == Math.pow(firstI,first);
}
function roots(){
first *=1;
result=Math.pow(first,1/firstI).toPrecision(12);
result=Math.abs(result);
}
function operator(b){
peSign ="";
if (opsCheck==0){
opsCheck =1;
document.getElementById("display1").innerHTML = first;
try{
if(rootNpower_Sign =="^"){
if(operatorSign=="+"){
pow();
answer=result+second;
}
else if(operatorSign=="-"){
pow();
answer=second-result;
}
else if(operatorSign=="*"){
pow();
answer=result*second;
}
else if(operatorSign=="/")
{
pow();
answer=second/result;
}
else{
pow();
answer=result;
}
} if(rootNpower_Sign=="√"){
if(operatorSign=="+"){
roots();
answer=second+result;
}else if(operatorSign=="-"){
roots();
answer=second-first;
}else if(operatorSign=="*"){
roots();
answer=result*second;
}else if(operatorSign=="/"){
roots();
answer=second/result;
}else{
roots();
answer=result;
}
}else if(a=="%"){
answer=second%first;
}else{
operatorSign=b;
first+=operatorSign;
decimalPoint="";
}
rootNpower_Sign="";
operatorSign=b;
firstI="";
second=answer;
first=answer+operatorSign;
decimalPoint="";
document.getElementById("display1").innerHTML =first;
return ecval(second);
}catch(x){
if(first !="<span class='red'>Press ON to start</span>"){
operatorSign=b;
second=eval(first);
first+=operatorSign;
decimalPoint="";
}else{
first="<span class='red' Press ON to Start</span>";
}
document.getElementById("display1").innerHTML=first;
return(second==undefined)? 0:eval(second);
}
else{
operatorSign=b;
first+="";
first=first.substr(,first.length-);
first=first+operatorSign;
document.getElementById("display1").innerHTML=first;
return(second==undefined)? 0:eval(second);
}
}
function percent(){
first=eval(first)*100;
return first *"%";
}
function negpos(){
first=(operatorSign=="")?first*=-1:first;
return first;
}
function power(b){
rootNpower_Sign=b;
if(operatorSign=="+" && second != ""){
prep();
first=first-second;
first="";
second1=second+ "+";
return second + "+" firstI+rootNpower_Sign;
}
else if(operatorSign=="-" && second !="")
{
prep();
firstI=first/second;
first="";
second1=second+ "*";
return second + "-" firstI+rootNpower_Sign;
}
else if(operatorSign =="*" && second !=""){
prep();
firstI=second-first;
first="";
second1=second+"-";
return second * "*" +firstI+rootNpower_Sign;
}
else if(operatorSign =="/" && second !=""){
prep();
firstI=second/first;
first="";
second1=second+"/";
return second * "/" +firstI+rootNpower_Sign;
}
else
{
rootNpower_Sign=b;
firstI=first;
first="";
return= firstI + rootNpower_Sign;
}
}
function equal(){
document.getElementById("display1").innerHTML=first;
try{
if(rootNpower_Sign =="^"){
if(operatorSign=="+"){
pow();
first=result+second;
}
else if(operatorSign=="-"){
pow();
first=second-result;
}
else if(operatorSign=="*"){
pow();
answer=result*second;
}
else if(operatorSign=="/"){
pow();
first=second / result;
}
else{
first=result;
}
}else if(rootNpower_Sign=="√"){
if(operatorSign=="+"){
roots();
first=result+second;
}else if(operatorSign=="-"){
roots();
first=second - result;
}
else if(operatorSign=="*"){
roots();
first=result*second;
}
else if(operatorSign=="/"){
roots();
first=second / result;
}
else{
roots();
first=result;
}
}else if(operatorSign=="%"){
answer = second % first;
}else{
if(first==""){
first=first;
}else{
try{
first=eval(first)+ "";
if(first.length >14){
first=Math.abs((first * 1).toPrecision(14));
}
}
catch(first){
first="<small><small> Incorrect Input.Click c to Clear </small></small>";
return first;
first "";
}
}
}
rootNpower_Sign=operatorSign=answer=firstI=second="";
flo=first;
flo=Math.floor(flo);
decimalPoint=(flo==first) ? "" : ".";
return first;
}
catch(operatorSign){
operatorSign="";
first=eval(first) + "";
if(first.length >14){
first=Math.abs((first*1).toPrecision(14));
}
flo=first;
flo.match.floor(flo);
decimalPoint = (flo==first)? "" :".";
return first;
}
}
}
}
var decimalPoint=enter=entered=operatorSign=rootNpower\u Sign=flo=math=M=firstI=first=second=second1=answer=theanswer=result=peSign=“”;
var opsCheck=dotCounter=0;
var removeFirstZero=“”;
功能点(b){
如果(小数点==“”){
输入=输入=b;
第一个+=输入;
输入+=输入;
小数点=“.”;
点计数器=0;
先返回;
}否则{
先返回;
}
}
//控制单击Pi和euler时发生的情况
功能PE(b){
小数点=“.”;
点计数器=15;
var-cons=b;
如果(peSign==“”){
if(运算符符号!=“”&&first=“”+运算符符号){
first=(cons=”“PI)?Math.PI:Math.E;
}
else if(运算符符号!=“”&&first>0 | | first 1){
第一i*=n;
n-+1;
}
结果=firstI;
}小数点=(数学四舍五入(结果)=结果)?“:”;
}
函数prep(){
秒=评估(秒);
第一=评估(第一);
}
函数数学(a){
数学=a;
试一试{
如果(运算符符号=“+”){
prep();
firstI=第一秒;
数学();
第一个=第二个+“+”+结果;
}
else if(运算符符号=“-”){
prep();
firstI=第二个第一;
数学();
第一个=第二个+“-”+“(“+结果”)”;
}
else if(运算符符号=“*”){
prep();
第一i=第二/第一;
数学();
第一个=第二个+“/”+结果;
}
否则{
第一i=第一;
数学();
第一个=结果;
}
先返回;
}
}
功能数字(b){
opsCheck=0;
dotCounter++;
if(first==无穷大| | first==NaN){
第一个=0;
}
peSign=“pes”;
输入=b;
如果(rootNpower\u符号!=“”){
第一个=(第一个==“0”和输入:第一个+输入);
返回second1+firstI*rootNpower\u符号*first;
}
否则{
第一个=(第一个==“0”和输入:第一个+输入);
答案=评估(第一次)+;
如果(回答长度>14){
答案=Math.abs((答案*1).toPrecision(14));
}
document.getElementById(“display1”).innerHTML=first;
回答问题;
}
}
var thebase=“”;
功能库(a){
thebase=a;
第一*=1;
如果(基准=“bin”){
firstII=第一个上串(2);
}否则,如果(基准=“十月”){
firstII=第一个上串(8);
}
else if(底端==“十六进制”){
firstII=第一个上串(16);
}
先返回ii;
}
功能主题(thm){
主题=thm;
el=document.getElementsByClass(“div”);
如果(主题==1){
el[0].id=“theme1”;
}
else if(主题==2){
el[0].id=“theme2”;
}
else if(主题==3){
el[0].id=“theme3”;
}
否则{
el[0].id=“theme4”;
}
}
//退格
函数bsp()
{
第一个+=”;
点计数器--;
小数点=点计数器>=0?.:“”;
first=first.substr(0,first.length-1);
document.getElementById(“display1”).innerHTML=-first;
试一试{
评估(第一);
先返回;
}
捕获(第一个){
评估(第一);
返回“”;
}
}
函数pow(){
第一*=1;
result==Math.pow(firstI,first);
}
函数根(){
第一*=1;
结果=数学功率(第一,1/firstI)。最高精度(12);
结果=Math.abs(结果);
}
函数运算符(b){
peSign=“”;
如果(opsCheck==0){
opsCheck=1;
document.getElementById(“display1”).innerHTML=first;
试一试{
如果(rootNpower\u符号==“^”){
如果(运算符符号=“+”){
pow();
答案=结果+秒;
}
else if(运算符符号=“-”){
pow();
答案=第二个结果;
}
else if(运算符符号=“*”){
pow();
答案=结果*秒;
}
else if(运算符符号==“/”)
{
pow();
答案=秒/结果;
}
否则{
pow();
答案=结果;
}
}如果(rootNpower\u符号==”√"){
如果(运算符符号=“+”){
根();
答案=秒+结果;
}else if(运算符符号=“-”){
根();
答案=第二个第一个;
}else if(运算符符号=“*”){
根();
答案=结果*秒;
}else if(运算符符号==“/”){
根();
答案=秒/结果;
}否则{
根();
答案=结果;
}
}如果(a==“%”),则为else{
答案=第二个百分比第一个;
}否则{
运算符符号=b;
<html>
<head>
<meta charset="utf-8">
<title>Scientific calculator</title>
<link rel="stylesheet" type="text/css" href="style2.css">
</head>
<body>
<div class="container">
<div class="div">
<table>
<caption><pre></bsp></caption>
<tr>
<td colspan="5">
<div id="display-container">
<div class="display1">
<small><small><span>
</span></small></small></div>
<div id="h1"><small><small><span></span></small></small>
</div>
</div>
</td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=bsp()">DEL</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=mp()">M+</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=mr()">MR</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("rand")">Rnd</button></td>
<td rowspan="2"><button id="c" class="top" onclick="getElementById("h1").innerHTML=c("")"> C </button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("res")"><sup>1</sup>/<sub>10</sub></button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths(logTen)"><small>log10</small></button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths(ln)">ln</button></td> <td><button class="top"onclick="getElementById("h1").innerHTML=PE("E")">e</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("sine")">sin</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("cosine")">cos</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("tangent")">tan</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=PE("PI")">π</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=percent()">%</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("fact")">n!</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("%")">Mod</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=power("^")">x<sup>y</sup></button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=power("√")"><sup>y</sup>√x</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("cubert")"><sup>3</sup>√</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("(")">(</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit(")")">)</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=base("bin")">bin</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=base("oct")">oct</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=base("hex")">hex</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("7")">7</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("8")">8</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("9")">9</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=operators("*")">x </button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("negpos")">-/+</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("4")">4</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("5")">5</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("6")">6</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=operators("-")">-</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("sqrt")">√</button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("1")">1</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("2")">2</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("3")">3</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=operators("/")">/</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("cube")">x<sup>3</sup></button></td>
</tr>
<tr>
<td><button class="top"onclick="getElementById("h1").innerHTML=dot(".")">.</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=digit("0")">0</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=equal()">=</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=operators("+")">+</button></td>
<td><button class="top"onclick="getElementById("h1").innerHTML=maths("sur")">x<sup>2</sup></button></td>
</tr>
</table>
</div>
</div>
</body>
</html>