我对NodeJS很新,所以这个任务是我开始接受NodeJS培训的第一步。我遇到了一个我根本不懂的问题。一个简单的帮助对我来说是伟大的。
这是我的代码
var rect = {
perimeter: function (x,y) {
return (2*(x+y));
},
area: function (x,y) {
return (x*y);
}
};
function solveRect(l,b) {
console.log("Solving for rectangle with l = " + l + " and b = " + b);
if (l < 0 || b < 0) {
console.log("Rectangle dimensions should be greater than zero: l = " + l + ", and b = " + b);
}
else {
console.log("The area of a rectangle of dimensions length = " + l + " and breadth = " + b + " is " + rect.area(l,b));
console.log("The perimeter of a rectangle of dimensions length = " + l + " and breadth = " + b + " is " + rect.perimeter(l,b));
}
}
solveRect(2,4);
solveRect(3,5);
solveRect(-3,5);
我遇到的错误是
console.log("The area of a rectangle of dimensions length = " + l + " and
^^^^^^
SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3