<body>
<p id="output">Dear Computer, is it my birthday yet?</p>
<p id="somethingelse"></p>
</body>
JavaScript
/* 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)
var isItIrinasBirthday = function (today) {
var mybirthday = new Date(1985, 06, 16);
if (mybirthday.getMonth() == today.getMonth() && mybirthday.getDate() == today.getDate()) {
$("#output").after("<br>Happy Birthday! <br>");
return true;
} else {
$("#output").after("<br>Not your birthday yet, human! <br>");
return false;
}
}
/* 6/6 : Beautiful! In practical use, you wouldn't want to put the output inside the function, rather set it based on the caller. So you could go:
if(isItIrinasBirthday(someDateInput)) { $("#output").after("It's your birthday!"); } else {$("#output").after("It's not your birthday!"); }
I'm not grading on how you demo your functions, though. Nice touch using 'after' instead of the 'text' function I supplied, since this keeps an output buffer. I should recommend the class use that instead on future work. */
//2 - Create a function called isToday{YOURNAME}Birthday, which calls the function you wrote in Step 1, passing in today's Date. (6)
var isTodayIrinasBirthday = function () {
var today = new Date(2014, 0, 30);
return isItIrinasBirthday(today);
};
// 6/6 : Yep.
isTodayIrinasBirthday();
//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
for (var checkDate = new Date(); !(checkDate.getDate() == mybirthday.getDate() && checkDate.getMonth() == mybirthday.getMonth());
checkDate.setDate(checkDate.getDate() + 1)) {
isTodayIrinasBirthday();
$("#somethingelse").after("<br>Now you shell...
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.