cannot read property of undefined(入门级qwq自学小白求教
这是一个学生网页开发比赛的报名测试qwq所以不是完整的
具体来说就是完成5个函数,然后它会随机输入这样格式的timeseries:
[
{
"date": "2016-05-04",
"price": 1.234
},
...
]
Time series might not be in chronological order.
Each function should return a single value.
其中有一个函数是找出时间最前的然后return相应的price,然后它一直报错cannot read property 'price' of undefined……我这两天才开始学,一边试一边写但是这个怎么都解决不了_(:з ∠)_百度错误原因也根本不明白
求教啊啊啊qwqqqqqq
我写的代码是这样子↓
function first(timeseries) {
// ↑↑函数名称是题目本来就有的
var count = 0;
var mintime = 99999999,mini;
var date = new Array();
if(timeseries === null || timeseries === undefined){
return;
}
for(var j = 0;j < timeseries.length;j ++){
//document.write("j:" + j + " ");
count = 0;
for(var x in timeseries[j]){
count = count + 1;
//document.write("ct:" + count + " ");
}
if(timeseries[j] === undefined || timeseries[j] === null){
return;
}
if(count != 2){
if(timeseries[j].date === undefined || timeseries[j].date === null){
throw"date is missing";
}else{
return undefined;
}
}
}
for(var k = 0;k < timeseries.length;k ++){
if(checkdate(timeseries[k]) == 1 && checkprice(timeseries[k]) == 1){
//document.write(" k:" + k + " ");
date[k] = seriestodate(timeseries[k]);
//document.write(" date[k]:" + date[k] + " ");
if(cprdate(mintime,date[k]) === 1){
mini = k;
mintime = date[k];
//document.write(" mini:" + mini + " mintime:" + mintime);
}
}else{
throw"date is missing";
}
}
return timeseries[mini].price;
}
求教qwqqqqqq
谢谢!!!