Jump to content


@$!-!i$!-!

Member Since 07 Dec 2014
Offline Last Active Aug 11 2015 09:11 AM
-----

Posts I've Made

In Topic: Chapter 9 Delete Sticky

11 July 2015 - 01:01 PM

Never mind.. 

I tested this again after clearing the localStorage and everything works fine.

We need not use the if condition !


In Topic: Chapter 4 Troubles

01 July 2015 - 02:56 PM

Hi Cakewok, 

 

The solution below works too !

<!doctype html>
<html>
	<head>
		<title>Javascript objects and functions</title>
		<meta charset="utf-8">
		<script>
//		function init(){
			var movie1={
				title : "Plan 9 from Outer Space",
				genre : "Cult Classic",
				rating : 5,
				showtimes : ["3:00pm","7:00pm","11:00pm"]
			};
			var movie2={
				title : "Forbidden Planet",
				genre : "Classic Sci-fi",
				rating : 5,
				showtimes : ["5:00pm","9: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);
			nextShowing = getNextShowing(movie2);
			alert(nextShowing);
//			}			
//			window.onload = init;
			
		</script>
	</head>
	<body>
	</body>
</html>

In Topic: Chapter 4 Troubles

01 July 2015 - 02:00 PM

Hi Cakewok, 

 

I was facing the same problem and found out the solution just now.Your code indirectly helped me, so Thank You !

 

For your code, I suggest putting 

 

var nextShowing = getNextShowing(movie);

alert(nextShowing);
within the init function.
Please see my code below:
<!doctype html>
<html>
	<head>
		<title>Javascript objects and functions</title>
		<meta charset="utf-8">
		<script>
		function init(){
			var movie1={
				title : "Plan 9 from Outer Space",
				genre : "Cult Classic",
				rating : 5,
				showtimes : ["3:00pm","7:00pm","11:00pm"]
			};
			var movie2={
				title : "Forbidden Planet",
				genre : "Classic Sci-fi",
				rating : 5,
				showtimes : ["5:00pm","9: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);
			nextShowing = getNextShowing(movie2);
			alert(nextShowing);
			}			
			window.onload = init;
			
		</script>
	</head>
	<body>
	</body>
</html>

In Topic: Chapter 11 Page 516-517

04 June 2015 - 04:38 PM

Never mind folks, turns out it was Internet Explorer.. :(  (dont know why even IE11 doesnt show the table structure)

The html shows up correctly in Firefox/Chrome.

So nothing wrong with the code.


In Topic: Arrangement Of Elements On Guis

04 April 2015 - 04:28 PM

Thank You #TM# and Toni !