我正在研究输入橙色价格和购买橙子数量以及计算总成本的简单问题。 请检查此代码,并告诉我出错的地方。
var numberofOranges;
var costofOrange;
var orangeCost = function (costofOrange, numberofOranges) {
var Cost = costofOrange * numberofOranges;
return Cost;
};
confirm ("Confirm Number of Oranges you are buying", numberofOranges, costofOrange);
if ((numberofOranges === > 0 && typeof(numberofOranges)!= "string") && (costofOranges === > 0 && typeof(costofOranges)!= "string")) {
console.log("Cost of" + numberofOranges + "Oranges is" + (orangeCost(numberofOranges));
}
else {
console.log("Enter valid input");
}
答案 0 :(得分:1)
这应该有效
(function () {
var numberofOranges;
var costofOrange;
var orangeCost = function (costofOrange, numberofOranges) {
var Cost = costofOrange * numberofOranges;
return Cost;
};
numberofOranges = Number(prompt("Confirm Number of Oranges you are buying"));
costofOrange = Number(prompt("Confirm Cost of Oranges"));
console.log(costofOrange + " : " + numberofOranges);
if (( !isNaN(numberofOranges) && numberofOranges >= 0) && ( !isNaN(costofOrange) && costofOrange >= 0)) {
console.log("Cost of" + numberofOranges + " Oranges is " + orangeCost(costofOrange, numberofOranges) );
}
else {
console.log("Enter valid input");
}
})();
要记住一些事情,