[英]I have written this code but it is not showing any outputs. Why is this happening?
I have written this code but I am completely not sure the way I did is correct. 我已经编写了这段代码,但是我完全不确定我做的方法是否正确。 Is there anyone that can give me some guidance?
有没有人可以给我一些指导?
numbers
and assign an empty array to it. numbers
的变量,并为其分配一个空数组。 Array.push()
method, insert the numbers 0
to 9
into the array you named numbers. Array.push()
方法,将数字0
到9
插入命名为数字的数组中。 Array.push()
method correctly by console logging the first item in the array. Array.push()
方法。 car
and assign an empty object to it. car
变量,并为其分配一个空对象。 colour
and assign it the value of "black"
. colour
的属性,并将其值指定为"black"
。 var numbers = []; for (var i=0; i < 10; i++){ numbers.push(i); console.log(i[1]) console.log(i[9]) } var car = {};
var numbers = [];
for(var i=0; i<10; i++) {
numbers.push(i)
}
console.log(numbers[0]);
var lastIndex = numbers.length - 1;
console.log(numbers[lastIndex]);
var car = {};
car.colour = 'black';
You have pushed numbers to an array numbers
, but after this you have mixed up variables numbers
and i
. 您已经将数字推到数组
numbers
,但是在此之后,您将变量numbers
和i
混合了。 Variable i
is not an array. 变量
i
不是数组。 Except this your console.log
is in the for
loop and this is mistake too. 除此之外,您的
console.log
处于for
循环中,这也是错误的。
I have corrected your code: 我已更正您的代码:
var numbers = []; for (var i = 0; i < 10; i++){ numbers.push(i); } console.log(numbers[1]); //1 console.log(numbers[9]); //9 var car = {}; car.colour = 'black'; console.log(car.colour); //black
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.