谢谢!
编辑2:功能"功能"当我定义"电视"直接在控制台内,但除此之外,我无法弄清楚如何在代码中定义电视。我把它从一开始();功能,因为我认为它可能超出范围。这也不起作用。
// Program Name: Television Store
// Television Store Website.
/* Constructor Function: */
function TelInput(ret, man, scr, conf, dis) {
this.ret = parseInt(ret, 10);
this.man = man;
this.scr = parseInt(scr, 10);
this.discount = this.ret * 0.9;
this.dis = dis;
this.conf = conf
};
var start = function(){
/* Initial Variables */
var screen = prompt("Enter the screen size of TV in inches: ");
var manufacturer = prompt("Enter the manufacturer of TV: ");
var retail = prompt("Enter the retail value of TV: ");
var priceConf = confirm("Apply the 10% discount?");
var dispValues = confirm("Display Values when Finsihed?");
/* Display the Values */
console.log(television.ret);
console.log(television.man);
console.log(television.scr);
console.log(television.discount);
if(television.conf){
document.getElementById("l4").innerHtml = "Discounted Price: " + television.dis;
}
};
console.log("Program Completed."); // Confirm Javascript functions.
start(); // Start function.
var television = new TelInput(retail, manufacturer, screen, priceConf, dispValues); // Create object
答案 0 :(得分:0)
如果telInput
应该是构造函数:
使用new
:var television = new telInput(retail, manufacturer, screen, priceConf, dispValues);
进行调用。现在,属性ret
,man
等将分配到window
,television
将分配到undefined
。
Pascal-case构造函数:TelInput
。这是一个非常强大的惯例。请参阅this。
其他一些问题:
您没有将dis
和conf
分配给任何媒体资源:添加this.dis = dis; this.conf = conf
。
this.discount = ret * 0.9;
这应该是this.discount = this.ret * 0.9;
,因为this.ret
包含已解析的值。