-1
자바 스크립트 계산기를 사용할 수없는 문제가 있습니다. 브라우저에 표시되면 해당 부분은 반환 된 대답 대신 실제 코드 줄을 표시합니다. 이것은 내가 지금까지 가지고있는 것이다. 계산은 b()
이며 하단의 document.write()
에 인쇄됩니다.JavaScript : 변수를 사용하는 계산기
자바 스크립트 :
//*Note that this is an external JavaScript file*
function a(a1,a2,a3) {
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
this.a4 = b;
}
var abc = new a("2", "80", "1000");
var def = new a("1.5", "40", "512");
var ghi = new a("1", "20", "256");
//Below is the calulation function I'm having problems with
function b() {
var calculation;
calculation = 500;
calculation+=(this.a1 = 2) ? 200 : 100;
calculation+=(this.a2 = 80) ? 50 : 25;
calculation+=(this.a3 = 1000) ? 150 : 75;
return calculation;
}
var returned_value_abc = abc.a4();
var returned_value_def = def.a4();
var returned_value_ghi = ghi.a4();
document.write("Abc object: ");
document.write("<br/>");
//Below is code to print out returned calculation value
document.write("Value: "+abc.a4);
document.write("<br/>");
document.write("<br/>");
document.write("Def object: ");
document.write("<br/>");
//Below is code to print out returned calculation value
document.write("Value: "+def.a4);
document.write("<br/>");
document.write("<br/>");
document.write("Ghi object: ");
document.write("<br/>");
//Below is code to print out returned calculation value
document.write("Value: "+ghi.a4);
document.write를 사용하지 마십시오. http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice –