/* COMP9633 - Quiz #2
* In today's quiz, we'll put what you've learned about functions to the test. We'll both
* call functions other people have written, and write a new function ourselves.
* 1 - Create a function called isIt{YOURNAME}Birthday, which takes a date input, and checks
* if that date is the date of your birthday, returning a boolean. (6)
* 2 - Create a function called isToday{YOURNAME}Birthday, which calls the function you wrote (6)
* in Step 1, passing in today's Date.
* 3 - Write a loop that increments the dates until it is your birthday, then alert "Happy Birthday!" (2)
* -- for all the above, call your functions and write some output to demo them */
/* BONUS:
Use a constructor other than the one I provided to set up your date (2)
BONUS: Write a function howManyDaysUntil{YOURNAME}sBirthday(). That's all. (4)
*
/* Useful link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date */
$("#output").text("http://jsfiddle.net/jkoudys/ZcYVL/");
/* To make a new date, starting a year ago yesterday, it's: */
var date = new Date(2013, 0, 29);
/* Dates are tricky to compare; test that the month and day are the same */
if (date.getMonth() == today.getMonth()) alert("These two dates have the same month!");
if (date.getDate() == today.getDate()) alert("These two dates have the same day of the month!");
/* Here's a nice way to iterate through dates; there are many ways to do it, but I'm not testing you on Date so feel free to just copy mine */
for (var checkDate = new Date(); !isItMyBirthday(checkDate); checkDate.setDate(checkDate.getDate() + 1)) {}
/* So a basic way to check if your dates match on day of the month and month is */
dateA.getMonth() == dateB.getMonth() && dateA.getDate() == dateB.getDate()
for (var a = 1; a != 10; a = a + 1) {}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.