Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
troy beckett
12,035 PointsWhat's wrong with my object property title?
Something is wrong with the way I am using the property 'title' in both my movie objects and I'm not sure why? Any ideas would be much appreciated.
var movie1 = {
title = "huhu",
genre = "Cult Classic",
rating = 2,
showtimes = ["3:00pm","7:00pm","11:00pm"]
};
var movie2 = {
title = "lolo",
genre = "Classic Sci-fi",
rating = 4,
showtimes = ["4:00pm","8:00pm","12:00pm"]
};
function getNextShowing(movie) {
var now = new Date().getTime();
for (var i = 0; i< movie.showtimes.length; i = i + 1){
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();
}
window.onload = movie;
function movie(){
var nextShowing = getNextShowing(movie1);
alert(nextShowing);
nextShowing = getNextShowing(movie2);
alert(nextShowing);
};
2 Answers
Samuel Webb
25,370 PointsThe problem is that you're using an = sign in your objects. Use a colon instead. This is what you're doing:
title = "Some title"
Do this instead:
title: "Some title"
That should fix the issue. And make sure you do that with all your object properties, not just the title.
troy beckett
12,035 PointsThanks
Samuel Webb
25,370 PointsNo problem. Glad to help.