PDA

View Full Version : Christmas Challenge: Day 9



Chippiewill
09-12-2011, 06:51 PM
Today's Challenge is another coding one (Obviously!). You must create a web script (With only, HTML PHP, MySQL and Javascript) which counts down to December 25th 2011, 00:00:00. You may think, wow this is easy, and it is, however you are not being judged on speed, no, you are being judged on:

- Quality of coding
- Features of Script
- Accuracy of time (If you take into account latency that will be very interesting)

The best scripts will either be, Javascript auto updating, or PHP with GD libraries to make a dynamic image.

Please do make an attempt even if you don't think you're very good, you might learn something!

PRIZE: TWO months of Christmas VIP

Note: This is not an Official Habbox Competition

triston220
11-12-2011, 02:33 PM
These coding competitions are a great idea. :)

Chippiewill
11-12-2011, 07:08 PM
If I receive no entry of this challenge I will run the months over onto something else.

Also if people have no idea how to do this then:

1324771200 - time() = Number of seconds until christmas day

Divide this by 60, the remainder is your number of seconds
Divide that by 60, the remainder is the number of minutes
Divide that by 24 to find the number of days , the remainder is the number of hours


These coding competitions are a great idea. :)
Thanks.

Chippiewill
13-12-2011, 03:54 PM
Well, nobody took a bite unfortunately. I just chucked this together in about ten minutes:


<?php
$time = 1324771200 - time();

$times = $time % 60;
$time = floor($time / 60);

$timem = $time % 60;
$time = floor($time / 60);

$timeh = $time % 24;
$time = floor($time / 24);

print($time." Days, ".$timeh." Hours, ".$timem." Minutes, ".$times." Seconds.");
?>

Which results in something like "11 Days, 8 Hours, 6 Minutes, 43 Seconds."

I might still be willing to offer a prize for prettying it ;)

Chippiewill
13-12-2011, 04:21 PM
Got bored and fixed some errors for when the time till christmas is negative and I made it so it fixes itself every news years day for the next year:


<?php
$christmas = mktime(0,0,0,12,25,date("Y")); // Finds the timestamp for Christmas at midnight of the current year (Hours,Minutes,Seconds,Months,Days,Year), date("Y") finds the current year

$time = $christmas - time(); //Finds seconds between Christmas at midnight and the time now.

if($time <0) {print("Merry Christmas");} // Prevents errors if it is beyond midnight

else { // Adds an exception

$times = $time % 60; // Finds the number of seconds as a result of finding the remainder of dividing by 60
$time = floor($time / 60); // Effectively removes those seconds from the total by dividing by 60 and then flooring

$timem = $time % 60; // Finds the number of minutes as a result of finding the remainder of dividing by 60
$time = floor($time / 60); // Effectively removes those minutes from the total by dividing by 60 and then flooring

$timeh = $time % 24; // Finds the number of hours as a result of finding the remainder of dividing by 24
$time = floor($time / 24); // The number of hours is the floored value of dividing the number of hours by 24

print($time." Days, ".$timeh." Hours, ".$timem." Minutes, ".$times." Seconds.");

}
// The End
?>

Zuth
13-12-2011, 05:20 PM
Hows this for jazzing it up?

http://b3nz.co.uk/test1/countdowntochristmas.php

Chippiewill
13-12-2011, 05:27 PM
You're certainly in the lead.. for now.

Zuth
13-12-2011, 05:29 PM
lol, watch [@]@Recursion[/@] come pown me :(

Recursion
13-12-2011, 05:42 PM
lol, watch [@]@Recursion[/@] come pown me :(

I do Python, not PHP!

Zuth
13-12-2011, 05:46 PM
I do Python, not PHP!

No idea what that is, but fingers crossed :P

Chippiewill
13-12-2011, 06:01 PM
I had a little play around with image gd..



<?php
$christmas = mktime(0,0,0,12,25,date("Y")) + 3600; // Finds the timestamp for Christmas at midnight of the current year (Hours,Minutes,Seconds,Months,Days,Year), date("Y") finds the current year

$time = $christmas - time(); //Finds seconds between Christmas at midnight and the time now.

if($time <0) {print("Merry Christmas");} // Prevents errors if it is beyond midnight

else { // Adds an exception

$times = $time % 60; // Finds the number of seconds as a result of finding the remainder of dividing by 60
$time = floor($time / 60); // Effectively removes those seconds from the total by dividing by 60 and then flooring

$timem = $time % 60; // Finds the number of minutes as a result of finding the remainder of dividing by 60
$time = floor($time / 60); // Effectively removes those minutes from the total by dividing by 60 and then flooring

$timeh = $time % 24; // Finds the number of hours as a result of finding the remainder of dividing by 24
$time = floor($time / 24); // The number of hours is the floored value of dividing the number of hours by 24

$text = $time." Days, ".$timeh." Hours, ".$timem." Minutes, ".$times." Seconds.";
//print($text);
}
// The End

// Create a blank image and add some text
$im = imagecreatetruecolor(210, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, $text, $text_color);

// Output the image
//imagegd($im);
header('Content-Type: image/png');
imagepng($im);

// Free up memory
imagedestroy($im);
?>

Zuth
14-12-2011, 04:36 PM
[@]@Chippiewill[/@] when will the competition end since its now day 14? :S

Chippiewill
15-12-2011, 04:59 PM
I was just giving it breathing room, but considering all the entries.. I guess I win? Nah I kid, you win! What colour would you desireth?

Zuth
15-12-2011, 05:26 PM
I was just giving it breathing room, but considering all the entries.. I guess I win? Nah I kid, you win! What colour would you desireth?

Yay! Can I get the Christmas one please! :D

Want to hide these adverts? Register an account for free!