0
請看這段代碼,告訴我爲什麼不起作用?我認爲功能回報存在問題。感謝所有的回放。從函數返回值的問題
var movie1 = {
title: "Buckaroo Banzai",
genre: "Cult classic",
rating: 5,
showtimes: ["1:00pm", "3:00pm", "7:00pm"]
}
function getNextShowing(movie) {
var now = new Date().getTime();
for (var i = 0; i < movie.showtimes.length; i++) {
var showtime = getTimeFromString(movie.showtimes[i]);
if ((showtime - now) > 0) {
return "Next showing of " + movie.title + " is " + movie.showtimes[i];
}
}
return null;
}
function getTimeFromString(timeString) {
var theTime = new Date();
var time = timeString.match(/(\d+)(?::(\d\d))?\s*(p?)/);
theTime.setHours(parseInt(time[1]) + (time[3] ? 12 : 0));
theTime.setMinutes(parseInt(time[2]) || 0);
return theTime.getTime();
}
var nextShowing = getNextShowing(movie1);
alert(nextShowing);
感謝您的重播 – user1033392
@ user1033392 :)說感謝是不夠的。您必須投票回答此問題,並考慮將其標記爲您接受的答案,如果這能解決您的問題。 – Lion