-4

我正在关注 codecademy 上有关 Javascript 对象的教程,以下代码有效,它显示输出“莎莉”年龄为 39 岁,而霍尔顿斯年龄为 16 岁”,但编辑器说“opps,再试一次,错误”。请问代码有什么问题?

  function Person( name,age ) {
      this.name = name;
      this.age = age;
      this.species = "Homo Sapiens";
  }

  var sally = new Person("Sally Bowles", 39);
  var holden =  new Person("Holden Caulfield", 16);
  console.log("sally' age is " + sally.age + " while Holdens age is  " + holden.age );
4

1 回答 1

2

这是他们通过本教程所需要的:

function Person(name,age) {
  this.name = name;
  this.age = age;
  this.species = "Homo Sapiens";
}

var sally = new Person("Sally Bowles", 39);
var holden = new Person("Holden Caulfield", 16);
console.log("sally's species is " + sally.species + " and she is " + sally.age);
console.log("holden's species is " + holden.species + " and he is " + holden.age);

正如我在对您的问题的评论中所说,codeacademy 期望您通过一个特定的结果。有时并不明显。每当卡住时,您都应该检查他们的论坛,因为用户在特定课程中遇到此类问题时都会分享。

于 2013-07-17T08:30:50.360 回答