O'Reilly Forums: Movie Return Not Working - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Movie Return Not Working

#1 User is offline   Black_Haze 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 23-December 12

Posted 23 December 2012 - 08:56 AM

<script>
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 movie1 = {
	title: "Plan 9 from Outer Space",
	showtimes: ["3:00pm", "7:00pm", "11:00pm"],
	genre: "Cult Classic",
	rating: 2
};

var movie2 = {
	title: "ForbiddenPlanet",
	showtimes: ["5:00pm", "9:00pm"],
	genre: "Classic Sci-Fi",
	rating: 5
};

window.onload = function() {
var nextShowing = getNextShowing(movie1);
alert(nextShowing);
}
</script>


Placed everything into my head tag and uploaded it to my site and it's not working.. Now I tried to use php returns on my site yesterday as well and it's not working either. Not sure if it's just I'm messing up the coding or if returns literally aren't working, haha... Does anyone see anything wrong with it?

This post has been edited by Black_Haze: 23 December 2012 - 08:56 AM

0

#2 User is offline   Black_Haze 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 23-December 12

Posted 23 December 2012 - 03:05 PM

 lemuel, on 23 December 2012 - 12:53 PM, said:

The extra ')' at the end of this line:
return "Next showing of " + movie.title + " is " + movie.showtimes[i]);

is probably throwing an error.


Spent all morning looking and didn't even notice it. Thank you so very much! I appreciate your help
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users