我正在遵循代码学院的教程,我发现这很困难.
作业如下:
使用for-in循环打印出nyc的所有属性.
var nyc = {
fullName: "New York City",
mayor: "Michael Bloomberg",
population: 8000000,
boroughs: 5
};
// write your for-in loop here
for (var in nyc){
console.log(population);
}
Run Code Online (Sandbox Code Playgroud) 好吧,所以我有以下jquery代码,以及一个html页面,其中包含一些数字为1 - 2 -3 - 4的按钮和一个文本框.
当我点击一个按钮时,它会在文本框中显示该号码,但是当我再次点击它会删除该号码时,我如何使它像电话号码一样,所以我可以输入1234而不是每次都删除一个号码.
$('input[type="button"]').click(function() {
var txt = $(this).val();
$('#textbox').val(txt);
});
Run Code Online (Sandbox Code Playgroud) 当我运行以下代码时,我收到一个错误: TypeError: Object [object Object]
// create your Animal class here
function Animal(name, numLegs)
{
this.name = name;
this.numLegs = numLegs;
}
// create the sayName method for Animal
Animal.prototype = function sayName()
{
console.log("Hi, my name is [name]");
};
// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
Run Code Online (Sandbox Code Playgroud)
为什么?